Save As with a date in the file name

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
Good morning, All...

I know how to save a file using VBA with a date in the file name based on the day of the week, but now I need to save a file using a date that is sitting in a particular cell in the worksheet...

How do I do a Save As and use a date in cell B1 as part of the file name? For example, I want the file name to be:

CASH REPORT 02-15-2019

Based on the cell content of B1 showing as 2/15/19 and formatted as either text or date (I can change the formatting as needed if necessary).

Thanks for any help!
~ZM~
 
Looking for some additional help on this. The VBA opens the last report, which is a Shared workbook (I know, I know – not the best idea but it’s what Corporate wanted):

Code:
ChDir "\\SERVER\Cash Report"
    Workbooks.Open filename:="\\SERVER\Cash Report\DAILY CASH REPORT.xlsx"

It then makes the file non-shared:

Code:
ActiveWorkbook.ExclusiveAccess

Then the code performs some basic stuff like find/replace as well as a text-to-column and deleting of some unnecessary ‘garbage’ data.

At this point, I need to re-save the file in the Archive folder:

Code:
Dim Path As String
Dim filename As String
Path = "\\SERVER\Cash Report\Archives\"
filename = Range("A1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx"

ActiveWindow.Close

The file shows up in the Archive fine and has the right name in the file name based on whatever is sitting in cell A1, just like I had hoped…the rest of the code runs fine as well. But NOW, the archived file won’t open. I get a message of:

“Excel cannot open the file ‘CASH 3-8-2019.xlsx’ because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.”

Hoping someone here might know what the problem might be?

Thanks as always for your help! I’m leaving work for the day right now but will be back tomorrow if anyone has any ideas…thank you!
~ZM~
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hoping this reaches someone - been a few days with no responses, so trying again. I have a manual workaround that I've been doing for a couple of weeks until I can get this to work correctly.

Thanks for anyone who might be able to assist!

~ZM~
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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