How to Save with automatic filename plus today's date

Gary Drumm

Active Member
Joined
Feb 22, 2005
Messages
462
Is there a way to save a file and have it automatically put today's date in the file name?

Example: original File name = test.xls
desired file name = test072807.xls, or test.072807.xls, or test.07 28 07.xls

So, I open the file, do whatever, and then click save.
When I click save, it does one of the above, given that today is 7 28 07.

I tried to search for this topic, but search wasn't working well on my PC today.

Thanks,
Gary
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Place the following in the Workbook Object in VBE. Alter according to your needs:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strDate As String
strDate = Format(Now, " dd-mmm-yy")

ActiveWorkbook.SaveAs ("c:\test " & strDate & ".xls")

End Sub

Will create file as follows: test 28-Jul-07.xls
 
Upvote 0
Well, it's working, but not great?

It does save the file with a new file name + date, but as soon as it's finished, it causes Excel to crash, and offers two options, shut down, or shut down and notify Microsoft. When I clicked on datails, it listed appcrash, then excel.exe, then several other things in descending order.

I can live with it I suppose, but would prefer a seamless operation.

I'm using Office XP, on a Vista Home machine.

Any ideas would be appreciated.

Thanks,
Gary
 
Upvote 0
Joe,
Here is what you provided, plus my minor modifications.
I have Small Office XP, and Windows Vista.
Thanks,
Gary

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strDate As String
strDate = Format(Now, "mm-dd-yy")

ActiveWorkbook.SaveAs ("c:\My Documents\Blood Sugar\Blood Sugar " & strDate & ".xls")

End Sub
 
Upvote 0
Joe,
Yes, that's it exactly.
It gives me two options with the new file.
1. Close and go online to look for a solution
2. Close

I tried option 1, and it went to MS site to look for an update.

Thanks,
Gary
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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