How to know if a file exists

Has anyone got code to find out if a file exists before I use it in my app.
C
cuntacinteAsked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
sorry about the above,this is what I meant

if Dir("C:\Filename.txt") <> "" Then
   MsgBox "File Exists!"
end if
0
 
vinnyd79Commented:
If Dir("C:\Filename.txt") <> "" Then
0
 
cuntacinteAuthor Commented:
Thanks vinnyd79

C
0
 
RichWCommented:
Function FileExist(Fname As String) As Boolean
    On Local Error Resume Next
   FileExist = (Dir(Fname) <> "")
End Function

' Use
If FileExist("C:\MyFile.txt" Then
   Debug.Print "File Found"
End If

0
All Courses

From novice to tech pro — start learning today.