I have a textbox where the user can browse for a file or type the filename in the textbox. If the user types the filename, how do I check to see if that file exists or not?
Printable View
I have a textbox where the user can browse for a file or type the filename in the textbox. If the user types the filename, how do I check to see if that file exists or not?
Code:If Dir$("MyFileName") <> "" Then
'File exists
Else
'File does not exist.
End If
For user input:
Code:Private Sub Command1_Click()
Dim file As String
file = InputBox("What file do you want to check?")
If file <> "" Then
If Dir$(file) <> "" Then
'File exists
Else
'File does not exist.
End If
End If
End Sub
How do you check if a directory exists? Thanks.
If Dir$(Mydirectory,vbDirectory) <> "" Then 'that directory exists