Automatic Backup

dlafko1

New Member
Joined
Oct 22, 2017
Messages
33
I have an excel sheet that i want to store a backup anytime someone closes it. I have used this code but every time i hit save it puts it in the folder 2020 Internal External Postings & Database instead of going one more step and putting it the test folder. Which i will rename to back up. Not a a coding person so any help would be appreciated. This is also in a shared (Legacy ) Workbook.

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Saves the current file to a backup folder and the default folder
'Note that any backup is overwritten
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External  Postings & Database\test"
            ActiveWorkbook.Name
    ActiveWorkbook.Save
    Application.DisplayAlerts = True
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You need a backslash after the "test" folder name, i.e.
ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External Postings & Database\test\"
 
Upvote 0
Thanks added that but still not saving in there

VBA Code:
'Saves the current file to a backup folder and the default folder
'Note that any backup is overwritten
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External  Postings & Database\Backup\"
            ActiveWorkbook.Name
    ActiveWorkbook.Save
    Application.DisplayAlerts = True
End Sub

You need a backslash after the "test" folder name, i.e.
ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External Postings & Database\test\"
 
Upvote 0
Does it matter that the file location for the non back up file is in a different location then where i want to store the backup?
 
Upvote 0
Note that I think you need an ampersand between the end of the filepath and the filename, i..e
ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External Postings & Database\Backup\" & ActiveWorkbook.Name
 
Upvote 0
ok now I am getting this error
 

Attachments

  • Capture.PNG
    Capture.PNG
    22.3 KB · Views: 4
Upvote 0
Why do you have:
ActiveWorkbook.Save
inside of a BeforeSave event procedure?

I think that could throw you into an infinite loop.

Try this:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Saves the current file to a backup folder and the default folder
'Note that any backup is overwritten
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveCopyAs Filename:="W:\Job Posting Spreadsheet - Excel\2020 Internal External  Postings & Database\Backup\" & ActiveWorkbook.Name
    Application.DisplayAlerts = True
    Application.EnableEvents = True
End Sub
 
Upvote 0
Not sure what i am doing wrong but it still only saves in the main folder. This is in a shared drive idk if that matters.
 
Upvote 0
So, are you saying that it is NOT saving a copy to the "
"W:\Job Posting Spreadsheet - Excel\2020 Internal External Postings & Database\Backup\"
folder?

Do you have right to save it to that folder?

What happens if you manually try to browse and save a copy to that folder?
Are you able to, or do you get some sort of error message?
 
Upvote 0
I can save to that folder and dropped and dragged the original in and changed the name to backup so no problem there. Just when I hit the save button it saves 2 copies the original and then names the other one back up but puts them both in the save folder.
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

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