Example of FolderExists?

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.
 
R

Ron de Bruin

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
 

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