Check if a file exists

J

jonefer

This is something I keep forgetting to put in my library of "never forgets..."

Instead of checking for error 3043, how can I first check if a file/path
exists in VBA?
 
A

Allen Browne

Something like this:

Function FileExists(strFile As String) As Boolean
On Error Resume Next
FileExists = (Len(Dir$(strFile)) > 0)
End Function

Function FolderExists(strPath As String) As Boolean
On Error Resume Next
FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
End Function
 
Top