Background
We have all made the mistake of getting in a hurry and made changes to a spreadsheet and then determined we needed to save a backup copy of the original. This code makes it a one-click process to make that backup and continue with our process.
The code is composed of three procedures, two of which I use with all of my code. startCode() is placed at the beginning and endCode() is placed at the end of all my procedures. These procedures speed up processing and restore to normal operations the Excel environment after macro finishes. FileBackUp() is the procedure that takes the active workbook and creates a backup copy in the same file location as the active workbook. It then returns focus to the same active Workbook.
Sub startCode()
On Error Resume Next
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
.StatusBar = "In Macro"
End With
On Error GoTo 0
End Sub
Sub endCode()
On Error Resume Next
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.StatusBar = ""
End With
On Error GoTo 0
End Sub
Sub FileBackUp()
startCode
wkBookPath = ActiveWorkbook.Path
wkBookName = ActiveWorkbook.Name
CurrFile = wkBookPath & "/" & wkBookName
BackFile = wkBookPath & "/" & Format(Date, "mm-dd-yy") & "-" & wkBookName
ActiveWorkbook.SaveAs Filename:=BackFile
ActiveWorkbook.Close
Workbooks.Open Filename:=CurrFile
endCode
End Sub