PDA

View Full Version : [SOLVED:] backup of file with date



wilg
05-23-2012, 07:12 AM
Hi, I have the following which will save a backup of my file in a specified folder. But I need to add a date with time like now() into it so every time it saves it save with adding in the time with the filename so I can retrieve a backup 3 min ago for instance.

Any suggestions on this?


Sub backup()
On Error Resume Next
Fname = ActiveWorkbook.Name
ActiveWorkbook.SaveCopyAs ThisWorkbook.Sheets(".").Range("A41") & "BACKUP OF " & Fname
ActiveWorkbook.Save
End Sub

Thanks in advance.

Bob Phillips
05-23-2012, 09:44 AM
Sub backup()
On Error Resume Next
Fname = ActiveWorkbook.Name
ActiveWorkbook.SaveCopyAs ThisWorkbook.Sheets(".").Range("A41") & _
Format(Now, "yyyy-mm-dd hh:mm:ss") & "BACKUP OF " & Fname
ActiveWorkbook.Save
End Sub

CatDaddy
05-23-2012, 09:47 AM
& Format(Now, "HH:MM:SS")

wilg
05-23-2012, 10:02 PM
I have tried both ways but it doesnt seem to work.

If I take away the colon between the time portion it works like 12 00 00 as eg.

I seems like the format issue it the colons between the hh:mm:ss for some reason...

Bob Phillips
05-24-2012, 12:13 AM
You are absolutely right, : is an invalid character in a filename. I should have spotted that.