Alternative save method VBA

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,254
Office Version
  1. 2016
Hi, I am using the following code to save a backup version of my file each time I save. Does anyone have an alternative, this seems very slow and for some reason saves 3 times? It works but is very slow. Thank you in advance.


Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)If Not Success Then Exit Sub
Const backupFolder = "S:\BUSINESS IMPROVEMENT\BACKUPS"


Dim savedName As String
Dim backupName As String
Dim dotFinder As Long


Application.EnableEvents = False
savedName = ThisWorkbook.FullName
backupName = backupFolder & Mid$(savedName, InStrRev(savedName, "\"))
dotFinder = InStrRev(backupName, ".")
backupName = Left$(backupName, dotFinder) & Format$(Now(), "yyyymmddhhnnss.") & Mid$(backupName, dotFinder + 1)
If backupName = savedName Then Exit Sub
If Dir$(backupName) <> "" Then Kill backupName
ThisWorkbook.SaveAs backupName
Kill savedName
ThisWorkbook.SaveAs savedName
Application.EnableEvents = True


End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,216,113
Messages
6,128,903
Members
449,477
Latest member
panjongshing

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