Adding date for filename

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.
 
G

Guest

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
 
B

Bernie Deitrick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top