Saving file name with the last business day in YYYYMMDD format

mozza90

New Member
Joined
Mar 19, 2015
Messages
32
Hi,

Struggling to save an excel file with the following file name: "20181018 ALEX - Data.xlsx". I have the below code but the application.workday function doesnt seem to be working. Any ideas how to get around this?

File name should be yesterday's business date and then ALEX - Data.

Code:
ActiveWorkbook.SaveAs Filename:=  "filepath\" & Format(Application.WorkDay(Date, -1), "YYYYMMDD") & " ALEX - Data" & ".xlsx"

Thanks!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi, try this:

Code:
ActiveWorkbook.SaveAs Filename:=  "filepath\" & Format(VBA.Date - 1, "YYYYMMDD") & " ALEX - Data" & ".xlsx"
 
Last edited:
Upvote 0
In what way isn't it working?
 
Upvote 0
Thanks Kenny, that's nailed it. Been tearing my hair out!
Be warned that will give you yesterdays date, not the previous business day.
So if you run that on Monday it will return Sunday's date.
 
Upvote 0
Be warned that will give you yesterdays date, not the previous business day.
So if you run that on Monday it will return Sunday's date.

This is absolutely true, I apologize I misread the title.

Here is how to get it for business days:

Code:
ActiveWorkbook.SaveAs Filename:=  "filepath\" & Format(CDate(Evaluate("WORKDAY(TODAY(), -1)")), "YYYYMMDD") & " ALEX - Data" & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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