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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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