The following code creates a backup of the active wirkbook every 15 second ... Of course you can change the period as you like
Create a folder and name it "Test" in the partition C:\
The code in a module
------------------------------
- Code: Select all
Sub CreateBackup()
'The code creates backup of the workbook every 15 seconds. You can change the period
Dim strDate As String, strTime As String
'Format date
strDate = Format(Date, "DD-MM-YYYY")
'Format time
strTime = Format(Time, "hh.mm.ss")
'Cancel alert messages
Application.DisplayAlerts = False
With ActiveWorkbook
'Create a backup in the C:\Test folder. You can change the path
.SaveCopyAs Filename:="C:\Test\" & strDate & "_" & strTime & "_" & .Name
End With
Application.DisplayAlerts = True
'Run the macro again after 15 seconds
Application.OnTime Now + TimeValue("00:00:15"), "CreateBackup"
End Sub
And this code is in a workbook module
- Code: Select all
Private Sub Workbook_Open()
'Run the macro named "CreateBackup" after 15 seconds when workbook is opened
Application.OnTime Now + TimeValue("00:00:15"), "CreateBackup"
End Sub
Regards,
YasserKhalil From Egypt