ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Adding date for filename (https://www.excelbanter.com/excel-discussion-misc-queries/152362-adding-date-filename.html)

Wins07

Adding date for filename
 
How do automatically add date to my filename upon saving? I need to regularly
keep track of movements and need a daily backup of the excel file.

CLR

Adding date for filename
 
This would require a "Before Save" macro. If you are sure you want to add
VBA to your workbook just for this function, then post back and someone will
help.

Vaya con Dios,
Chuck, CABGx3



"Wins07" wrote:

How do automatically add date to my filename upon saving? I need to regularly
keep track of movements and need a daily backup of the excel file.


Bernie Deitrick

Adding date for filename
 
Put this code into the Codemodule of the ThisWorkbook Object.

It will save a dated/timed copy whenever you save. It can be modified to only save a dated copy,
overwriting the previous saved copies from that day...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then Exit Sub
MsgBox "I'm about to save a dated copy...."
Application.EnableEvents = False
ActiveWorkbook.SaveCopyAs Filename:= _
Replace(ActiveWorkbook.Name, ".xls", _
" BU " & Format(Now, " yyyy-mm-dd hh-mm") & ".xls")
Application.EnableEvents = True

End Sub

HTH,
Bernie
MS Excel MVP


"Wins07" wrote in message
...
How do automatically add date to my filename upon saving? I need to regularly
keep track of movements and need a daily backup of the excel file.





All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com