Check if a file exists

G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top