Adding date for filename

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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
 
Back
Top