using the .folderexists() command

C

Charlie

How do I check to see if a folder exists: This must be close...
If FileSystemObject.folderexists(strResultLocation) = vbTrue Then
Debug.Print "Yes"
End If


....also, if it doesn't exist, how to I create it?
 
D

Douglas J. Steele

There's really no need to bother with FSO.

If Len(Dir(strResultLocation, vbDirectory)) > 0 Then
' the folder exists
Else
' the folder does not exist
MkDir strResultLocation
End If

Note that MkDir will not create nested folders (i.e.: If you want
C:\Folder1\Folder2, then C:\Folder1 must already exist), but I'm not sure
FSO can do that either.
 

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