Hi guys,
I have the following code which when I save my workbook it automatically saves to another backup location as well which is great but I want it to backup with a different file name each time so I can go back and restore which file I need to. If it backed up with date & time as the filename that would be perfect as I could go back and restore what I needed to.
Sub Auto_Save()
'
' Auto_Save Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Dim savedate
savedate = Date
Dim savetime
savetime = Time
Dim formattime As String
formattime = Format(savetime, "hh.MM.ss")
Dim formatdate As String
formatdate = Format(savedate, "DD - MM - YYYY")
Application.DisplayAlerts = False
Dim backupfolder As String
backupfolder = "Z:\My Documents"
ActiveWorkbook.SaveCopyAs Filename:=backupfolder & formatdate & " " & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "Backup Run. Please Check at: " & backupfolder & " !"
End Sub
I also have the following code in ThisWorkbook
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim backupfolder As String
backupfolder = "C:\Users\Admin\OneDrive"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name
End Sub
I have the following code which when I save my workbook it automatically saves to another backup location as well which is great but I want it to backup with a different file name each time so I can go back and restore which file I need to. If it backed up with date & time as the filename that would be perfect as I could go back and restore what I needed to.
Sub Auto_Save()
'
' Auto_Save Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Dim savedate
savedate = Date
Dim savetime
savetime = Time
Dim formattime As String
formattime = Format(savetime, "hh.MM.ss")
Dim formatdate As String
formatdate = Format(savedate, "DD - MM - YYYY")
Application.DisplayAlerts = False
Dim backupfolder As String
backupfolder = "Z:\My Documents"
ActiveWorkbook.SaveCopyAs Filename:=backupfolder & formatdate & " " & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "Backup Run. Please Check at: " & backupfolder & " !"
End Sub
I also have the following code in ThisWorkbook
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim backupfolder As String
backupfolder = "C:\Users\Admin\OneDrive"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & ThisWorkbook.Name
End Sub