PDA

View Full Version : [SOLVED:] Creating a VBA Script to save in a current month's folder (create folder as needed)



spittingfire
12-15-2015, 10:16 AM
Hi All,

I need some help with writing a VBA script in excel to do the following save file function

1. the filename will have the following format "Cable SVL Page " & Format(Now, "mmmm dd, yyyy") & ".xlsm"
2. The file will run from it's current location but will save as the above filename and format in a different location.
3. The location to be saved in is "B:\NCC\ntsd\cable\" but the file will need to look for the current months' folder and save itself there.
4. If the current months' folder does not exist it will need to be created before saving. The format of the month is just the full name of the month e.g. November.

Any help will be appreciated.

Bob Phillips
12-15-2015, 11:20 AM
Dim folder As String

folder = "B:\NCC\ntsd\cable\" & Format(Date, "mmmm") & "\"
On Error Resume Next
MkDir folder
On Error GoTo 0
With ActiveWorkbook

.SaveAs Filename:=folder & .Name
End With

spittingfire
12-15-2015, 11:56 AM
Thanks for your help.

Works like a charm