I need to save a file ito a directory, but if the directory doesn't exist, I want to create it first.
Is there a simple way for Visual Basic to check for the existence of a directory? All help gratefully recieved.
Thanks for that.
I was hoping to do this without using the on error stuff, because I wanted to use that for something else withing the same subroutine. I am sure I have seen something on these boards, but I can't find it. V.Frustrating.
Have a look at the FolderExists method of the FileSystemObject in VBA help. You can use it in something like this (you'll need to set a reference to MS Scripting Runtime from the Tools-References menu): -
Public Sub CheckFolder()
Dim myFileSystem As New Scripting.FileSystemObject
Dim myFolder As Scripting.Folder
Dim DestFolder As String
Dim wb As Workbook
Dim ans As Integer
Dim PathAndFile As String
Set wb = ActiveWorkbook
DestFolder = "C:My Document"
PathAndFile = DestFolder & "" & wb.Name
If Not myFileSystem.FolderExists(DestFolder) Then
ans = MsgBox("Folder does not exist. Create it and save file?", vbYesNo + vbInformation)
If ans = vbYes Then