creates a backup file every 4 hours according to computer system time

Nikko

Board Regular
Joined
Nov 26, 2018
Messages
73
Hello all,
I have this code where the workbook with the command "save" also created a backup file.
But wants to create a backup file (like now) where it creates in background a backup file every 4 hours according to computer system time. Instead of using the "save" command.
Can someone help me and change the vba code so that it is possible ... if this is of course possible :) . I'm not a big VBA light, please be patient with me :)
VBA Code:
Option Explicit



Private Const Pfad As String = "\\WDMYCLOUD\Team\0 Niko\PLANER\Planer 2020\Backup\"

Private Const Dname As String = "Backup"



Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Dim Info As VbMsgBoxResult

   

    If Not ReadOnly Then

       

        If Not Saved Then

           

            If MsgBox("Die Mappe wurde noch nicht gespeichert." & vbLf & _

                "Soll diese Mappe gespeichert werden?", vbYesNo Or vbQuestion, _

                "Schließen und Speichern?") = vbYes Then

               

                With Application

                    .ScreenUpdating = False

                    .DisplayAlerts = False

                    .EnableEvents = False

                End With

                        Save

                                Sheets.Copy

                With ActiveWorkbook

                    .SaveAs Filename:=Pfad & Dname & Format$(Now, "yyyy-mm-dd - hh-mm"), FileFormat:=xlOpenXMLWorkbookMacroEnabled

                    .Close

                End With

                With Application

                    .ScreenUpdating = True

                    .DisplayAlerts = True

                    .EnableEvents = True

                End With

            Else

                Saved = True

               

            End If

        End If

    End If

End Sub



Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

   

    If Not ReadOnly And Not SaveAsUI Then

       

        With Application

            .ScreenUpdating = False

            .DisplayAlerts = False

        End With

       

        Sheets.Copy

        With ActiveWorkbook

            .SaveAs Filename:=Pfad & Dname & Format$(Now, "yyyy-mm-dd - hh-mm"), FileFormat:=xlOpenXMLWorkbookMacroEnabled

            .Close

        End With

       

        With Application

            .ScreenUpdating = True

            .DisplayAlerts = True

        End With

    End If

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If I included this command in the end, could it work?

VBA Code:
.OnTime Now + TimeValue("04:00:00"), "AutoSave"

Can use any help :)
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top