check if file exists

harrisw

Registered User.
Local time
Today, 20:13
Joined
Mar 27, 2001
Messages
131
Hi

I need to check whether a file exists before continuing the code.

Not sure haw to check if a file exists.

Thanks in advance
 
You need to add a reference to Microsoft.ScriptingRuntime

Then in your sub

Dim fso as New FileSystemObject

If fso.FileExists("Full Path") Then
 
If you prefer not to deal with references then use the Dir() function.

Code:
    If Dir("X:\YourFile.txt", vbNormal) <> "" Then
        MsgBox "Files exists."
    Else
        MsgBox "Files does not exist."
    End If
 

Users who are viewing this thread

Back
Top Bottom