Sub CheckIfFileExists()
Dim LRow As Integer
Dim LPath As String
Dim LExtension As String
Dim LContinue As Boolean
LContinue = True
LRow = 2
LPath = "C:\Users\Admin\Desktop"
LExtension = ".docx"
While LContinue
If Len(Range("B" & CStr(LRow)).Value) = 0 Then
LContinue = False
Else
If Len(Dir(LPath & Range("B" & CStr(LRow)).Value & LExtension)) = 0 Then
Range("C" & CStr(LRow)).Value = "No"
Else
Range("C" & CStr(LRow)).Value = "Yes"
End If
End If
LRow = LRow + 1
Wend
End Sub
The above code can find out if a file exists and output the result in row C when I hard code the path into
LPath = "C:\Users\Admin\Desktop"
However, I want to let the user input the path in, say cell D1 so that there is no need for the user to modify the VBA code
I tried replacing with LPath = Range("D1").Value
But it does not work
What should I do to allow the user to input the path in cell D1 ?
Bookmarks