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?

Improve company productivity with a Business Account.Sign Up

x
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.