Hi, I am using the below VBA code to save a time- and date-stamped backup copy of the Active excel file in a separate folder then reopen the Master (initial file) and close the backup copy, which is saved in a designated path. When I 'step in' the code it seems to be working fine. When I however execute the code from an Form Control button from within the Master excel file the code runs non-stop, giving the impression it has entered into an endless loop. Can you please help with what might be wrong with the below code?
------------------------------------------
------------------------------------------
VBA Code:
Sub Backup()
Dim ws As Worksheet
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim filepath As String
If ActiveWorkbook.Name = "[Active Excel Filename]" Then
If MsgBox("This action will save a copy of the file. Do you want to proceed?", vbYesNo) = vbYes Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.CalculateBeforeSave = False
filepath = "[path at which the backup file will be saved ]"
With ActiveWorkbook
.SaveAs filename:=filepath & Format(Now(), "ddmmyyyy hhmmss") & ".xlsb"
End With
Set wb1 = ThisWorkbook
Application.CalculateBeforeSave = True
Workbooks.Open "[path at which the master file is located]"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
wb1.Close
Else
End If
Else
End If
End Sub
Last edited by a moderator: