Save backup file with date and time in filename

L

lobster

I have very kindly been given a sub to create backups. Is it possible t
amend this so that the file name it creates for the backup includes th
date ? Basically I dont want to overwrite the backup file everytime an
I would like to be able to search through the backups periodically.

Sub Backup() 'kept in personal.xls & assigned to toolbar button
On Error GoTo BackupFile
MkDir CurDir & "\Backup"
BackupFile:
With ActiveWorkbook
MyWB = .Path & "\BACKUP\" & .Name
.SaveCopyAs MyWB
.Save
End With
End Sub

Would be really grateful if someone could have a look at this. It woul
be ideal if the file was named say...

04122003.xls

Many thanks
 
C

Chip Pearson

Change the line of code
MyWB = .Path & "\BACKUP\" & .Name
to
MyWB = .Path & "\BACKUP\" & Format(Now,"mm_dd_yyy_hh_mm_ss") &
..Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


lobster said:
I have very kindly been given a sub to create backups. Is it possible to
amend this so that the file name it creates for the backup includes the
date ? Basically I dont want to overwrite the backup file everytime and
I would like to be able to search through the backups periodically.

Sub Backup() 'kept in personal.xls & assigned to toolbar button
On Error GoTo BackupFile
MkDir CurDir & "\Backup"
BackupFile:
With ActiveWorkbook
MyWB = .Path & "\BACKUP\" & .Name
SaveCopyAs MyWB
Save
End With
End Sub

Would be really grateful if someone could have a look at this. It would
be ideal if the file was named say...

04122003.xls

Many thanks.
to creating financial statements
 

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