VBA Save file in dd.month format

mik1996

New Member
Joined
Mar 15, 2023
Messages
23
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hi there,

I'm just trying to ammend my code so that it will save the file depending on the date i.e most of my file locations are saved as:
01.January
02.February
03.March

Etc. currently my code saves it in/ or creates the folder 'March' but i just need to add the date number before the month if that makes sense and i can't work out how to add this. Please see current code below:

VBA Code:
Sub DateFolderSave_BS1495()
Dim strGenericFilePath      As String: strGenericFilePath = "K:\Finance\Protected Funding Sheets\Money In Funding\BS1495 Funding\"
Dim strYear                 As String: strYear = Year(Date) & "\"
Dim strMonth                As String: strMonth = MonthName(Month(Date)) & "\"
DateStamp = Format(Date, "dd-mm-yy")
Dim strFileName             As String: strFileName = ("BS1495 Funding" & " " & DateStamp)
Application.DisplayAlerts = False
' Check for year folder and create if needed
If Len(Dir(strGenericFilePath & strYear, vbDirectory)) = 0 Then
    MkDir strGenericFilePath & strYear
End If
' Check for month folder and create if needed
If Len(Dir(strGenericFilePath & strYear & strMonth, vbDirectory)) = 0 Then
    MkDir strGenericFilePath & strYear & strMonth
End If
' Save File
ActiveWorkbook.SaveAs Filename:= _
strGenericFilePath & strYear & strMonth & strDay & strFileName, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = True
' Popup Message
MsgBox "File Saved As: " & vbNewLine & strGenericFilePath & strYear & strMonth & strDay & strFileName
End Sub

Thanks,
Mik
 

Attachments

  • FolderSaveLocation.PNG
    FolderSaveLocation.PNG
    23.6 KB · Views: 14

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do you want to add the month number before the month name?

VBA Code:
    strMonth = Format(Date, "mm.Mmmm") & "\"
Ahhh yes didn’t realise it was that simple, sorry for the stupid question thank you very much
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top