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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

joefrench

Active Member
Joined
Oct 4, 2006
Messages
357
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

Gary Drumm

Active Member
Joined
Feb 22, 2005
Messages
462
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

Gary Drumm

Active Member
Joined
Feb 22, 2005
Messages
462
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

Gary Drumm

Active Member
Joined
Feb 22, 2005
Messages
462
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,186,366
Messages
5,957,448
Members
438,306
Latest member
Crystal_Blue

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
Top