Example of FolderExists?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

In VB help there is a reference made to FileSystemObject.
I would like to see an example of FolderExists...

I have code that creates a csv file and prompts the user
for a location to save the csv. But I don't want to have
the code bomb if the folder doesn't exist.

Thanks.
 
You can test if a folder exist with this

If Not fs.FolderExists(Dirname) Then

Sub MakeDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\MyDir2"
If Not fs.FolderExists(Dirname) Then
fs.CreateFolder Dirname
ActiveWorkbook.SaveAs Dirname & "\ron.xls"
Else
ActiveWorkbook.SaveAs Dirname & "\ron.xls"
End If
End Sub
 
Back
Top