You can use a function like
Function DirExists(PathName As String) As Boolean
If Dir(PathName, vbDirectory) = vbNullString Then
DirExists = False
Else
DirExists = True
End If
End Function
However, with this code if you pass in a filename (e.g., "C:\Test\Temp.txt")
the function will return True. If you want to ensure that PathName is really
a directory and not a file, use
Function DirExists(PathName As String) As Boolean
If Dir(PathName, vbDirectory) = vbNullString Then
DirExists = False
Else
If Dir(PathName, vbNormal) = vbNullString Then
DirExists = True
Else
DirExists = False
End If
End If
End Function
This will return True only if PathName is the name of an existing directory.
If PathName is a non-existent directory or the name of an existing file, it
will return False.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"windsurferLA" <(E-Mail Removed)> wrote in message
news:472ac064$0$24307$(E-Mail Removed)...
>I know this question has been asked before, but post has expired.
>
> I want to find out if a certain directory exists, and if not to make it.
> I know you can use if Dir$(file.xls)<>"" to detect files.
> I know I can use MkDir to make the directory if it doesn't exist.
>
> My problem is I don't want to trigger error with MkDir if the directory
> already exists.
>
> How do I test to determine if a specific directory exists?