Excel VBA: Save file, creating directory if it doesn't exist

Soldato
Joined
7 Mar 2011
Posts
6,859
Location
Oldham, Lancashire
I have successfully written a function that saves the file where it needs to go, if it exists. Its based on the date so S:blah/06 June/ 13 Tuesday/22:00.xslm. Works fine if the folder exists, but tomorrow that folder wont be there, next month Augusts folder wont be there either. I don't really trust the users to create the folders exactly as needed.

I'll post what I have so far at the bottom, but how do I get it to create directories that don't exist?

Code:
Sub SaveFile()
    Dim location As String

    location = "H:\Working\Shaw Update" & "\" & Format(Worksheets("Shaw Operational Update").Range("D2").Value, "MM MMMM\\DD DDDD\\") & Format(Worksheets("Shaw Operational Update").Range("D3").Value, "HH.00") & ".xlsm"

    ActiveWorkbook.SaveCopyAs (location)
End Sub
 
Back
Top Bottom