New Excel Forum

This forum has been moved to TeachExcel.

Ask all future questions in the new excel forum.

ExcelKey

Create backup of workbook every specific period

Free Excel Tips and Tutorials
Forum rules
This forum is closed.

All new posts should be made at our new Excel Forum at TeachExcel.com.

Create backup of workbook every specific period

Postby YasserKhalil » Fri May 01, 2015 4:08 pm

Hello everybody
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
Last edited by Don on Sat May 02, 2015 8:36 am, edited 1 time in total.
Reason: added code tags to the second section of code
YasserKhalil
Rookie
 
Posts: 7
Joined: May 1, 2015
Reputation: 0
Excel Version: 2013

Return to Excel Tips and Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest