auto save copy as a backup upon opening workbook

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
the workbook contains many sheets and queries and code
somehow things go wrong and there is no backup
is there a way to create an auto backup upon opening the workbook and save in a specific backup folder
can the code give a message box do you want to backup? if vbyes then backup
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
VBA Code:
Option Explicit

Sub workbook_open()

Dim FileName As String
Dim FileExt As String

FileName = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
FileExt = Right(ActiveWorkbook.Name, (Len(ActiveWorkbook.Name) + 1 - InStr(ActiveWorkbook.Name, ".")))

    If MsgBox("Would you like a back up of the file?", vbInformation + vbYesNo) = vbYes Then
        ActiveWorkbook.SaveCopyAs "C:\ ... your path goes here ... " & FileName & " - " & Format(Date, "dd.mmm.yyyy") & FileExt
    End If


End Sub
 
Upvote 0
Have you tried setting Always Create BackUp option when you saved the file?

  1. Display the Save As dialog box.
  2. Click the Tools option in the lower-right corner (next to Save button)
  3. Click General Options. - Excel should display the General Options dialog box.
  4. Check, Create Backup.
  5. Click OK.
  6. Continue saving the workbook.
see if this helps

Dave
 
Upvote 0
hi
i got this far
how do i correct this code to save in a different folder?

Sub Auto_Save()
Dim saveDate As Date
Dim saveTime As Variant
Dim formatTime As String
Dim formatDate As String
Dim backupFolder As String

saveDate = Date
saveTime = Time

formatTime = Format(saveTime, "hh.MM.ss")
formatDate = Format(saveDate, "DD - MM - YYYY")

Application.DisplayAlerts = False
backupFolder = ThisWorkbook.Path & "\"
ActiveWorkbook.SaveCopyAs Filename:=backupFolder & Replace(ActiveWorkbook.Name, ".xlsm", "") & " " & formatDate & " " & formatTime & ".xlsm"
Application.DisplayAlerts = True

MsgBox "Backup Successfully In The Path " & backupFolder
End Sub
 
Upvote 0
i am trying your code
it doesnt save into the specified folder
"M:\all\FI Coordinators - RBS & SRW\Backups"
it saves into
"M:\all\FI Coordinators - RBS & SRW"
and names the file backups
 
Upvote 0
i am trying your code
it doesnt save into the specified folder
"M:\all\FI Coordinators - RBS & SRW\Backups"
it saves into
"M:\all\FI Coordinators - RBS & SRW"
and names the file backups

Selecting the option I outlined is a built-in feature of Excel - the backup copy is saved in the same folder as the original File.
If you want to specify another folder then probably will need to use a macro to do this.

Dave
 
Upvote 0
.
Try adding an "\" at the end of the path : "M:\all\FI Coordinators - RBS & SRW\Backups\"
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
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