How to check if the directory exists?

  • Thread starter Thread starter ira
  • Start date Start date
I

ira

I try to save the file. I'd like to prevent the case when the path i
wrong - Temp directory doesn't exist - and show the warning by myself

ex. ThisWorkbook.SaveAs C:\Temp\1.xl
 
ira > said:
I try to save the file. I'd like to prevent the case when the path is
wrong - Temp directory doesn't exist - and show the warning by myself.

ex. ThisWorkbook.SaveAs C:\Temp\1.xls


You can use to the filesystem object and the folderexists method

Set fs = CreateObject("Scripting.FileSystemObject")

If fs.FolderExists("C:\Temp") Then
MsgBox "OK"
Else
MsgBox "not found"
End If

Set fs = Nothing

Keith
 
Ira,

Use the DIR function

Dir("C:\Temp", vbDirectory)

it returns blank if the directory does not exist

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top