JavaScript is not enabled!...Please enable javascript in your browser

جافا سكريبت غير ممكن! ... الرجاء تفعيل الجافا سكريبت في متصفحك.

-->
الصفحة الرئيسية

Excel VBA | Backup Automatically Every 15 Seconds

 

Welcome Back

Create a backup copy of the workbook (auto save) every specified period of time Backup Automatically Every 15 Seconds



I present to you a code that creates a backup copy of the workbook every 15 seconds, in anticipation of problems such as a sudden power outage or as a kind of caution so that you have more than one copy of your file, especially if the file is very important

The code creates the backup in the same path as the current workbook in a folder called Test, the folder is created automatically if it does not exist, and you can change the auto save path, and you can change the name of the folder to save the backups in, and you can change the time period required for the auto save process (The code is explained in detail to make it easier for you to modify it)

 

Finally, here is the code, which is made up of a code placed in a normal module like this

Sub Create_Backup()

    Dim strDate As String, strTime As String, directoryName As String

 

    strDate = Format(Date, "DD-MM-YYYY")

 

    strTime = Format(Time, "hh.mm.ss")

 

    Application.DisplayAlerts = False

 

        With ActiveWorkbook

            On Error Resume Next

                directoryName = ThisWorkbook.Path & "\Test\"

       

                MkDir directoryName

            On Error GoTo 0

   

            .SaveCopyAs Filename:=directoryName & strDate & "_" & strTime & "_" & .Name

        End With

    Application.DisplayAlerts = True

 

    Application.OnTime Now + TimeValue("00:00:15"), "Create_Backup"

End Sub

 

The second part of the code is placed in the classifier event like this

Private Sub Workbook_Open()
    ' [CreateBackup] 
    Application.OnTime Now + TimeValue("00:00:15"), "Create_Backup"
End Sub

 

Prepared by / Yasser Khalil Abu Al-Bara

الاسمبريد إلكترونيرسالة