Folder exist

J

JayM

I know that you can test if a file exists but can you test if a folder
exists. if so what is the VBA code for it?

Any help appreciated especially examples of code

Thanks
 
K

Karl E. Peterson

JayM said:
I know that you can test if a file exists but can you test if a folder
exists. if so what is the VBA code for it?

Lots of folks will advise something like this is the simplest way:

Private Function FolderExists(PathName As String) As Boolean
If Len(PathName) > 0 Then
On Error Resume Next
FolderExists = ((GetAttr(PathName) And vbDirectory) > 0)
Err.Clear
End If
End Function
 
D

Doug Robbins - Word MVP

You can make use of the fact that you will get a Run time error 76 if the
path does not exist when you use ChDir("path")

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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