VBA SaveAS Function

data808

Active Member
Joined
Dec 3, 2010
Messages
353
Office Version
  1. 2019
Platform
  1. Windows
I have a button assigned to a macro that will name the file with today's date in a specific folder. The folder it looks for is the current year. Everything is working great. Here is the code:

ActiveWorkbook.SaveAs Filename:="C:\Users\john.smith\Desktop\" _
& Format(Now(), "YYYY") & "\" _
& "recd" & Format(Now(), "MMDDYYYY") & ".xlsm"

However, in the current year folder I want to organize it by month and so I have 12 folders. Each folder is by the month and I also put a number for that month as the folder name. Here is an example of how the folder are named within the 2022 folder:

01 January
02 February
03 March
04 April
05 May
06 June
and so........

How do write the VBA so it looks for the month folder that it needs to be saved in? Each year the directory won't change except for the yearly folders that contain these 12 month folders. Thanks for the help.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You just need to use the MM MMMM format. So:

VBA Code:
ActiveWorkbook.SaveAs Filename:="C:\Users\john.smith\Desktop\" & Format(Now(), "YYYY") & "\" & Format(Now(), "MM MMMM") & "\" & "recd" & Format(Now(), "MMDDYYYY") & ".xlsm"

which results in:
C:\Users\john.smith\Desktop\2022\11 November\recd11052022.xlsm
Is that what you were after?
 
Upvote 0
Solution
You just need to use the MM MMMM format. So:

VBA Code:
ActiveWorkbook.SaveAs Filename:="C:\Users\john.smith\Desktop\" & Format(Now(), "YYYY") & "\" & Format(Now(), "MM MMMM") & "\" & "recd" & Format(Now(), "MMDDYYYY") & ".xlsm"

which results in:

Is that what you were after?
Excellent! Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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