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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,215,055
Messages
6,122,902
Members
449,097
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