check file existence

peggypph

Registered User.
Local time
Today, 21:22
Joined
Jan 2, 2004
Messages
33
I would like to have a routine to check file existence under VBA.

Pls. give me some example. Thanks
 
Code:
Dim fLen As Integer, filepath As String
filepath = "c:\SomeFile.txt"
On Error Resume Next
fLen = Len(Dir$(filepath))
If Err Or fLen = 0 Then
MsgBox ("The File Does Not Exist")
Else
MsgBox ("The File Does Exist")
End If

Is this what you are after?
 
Code:
If Dir("C:\Temp\testing.txt") <> "" Then
    MsgBox "File does exist."
Else
    MsgBox "File does not exist."
End If
 

Users who are viewing this thread

Back
Top Bottom