Creating a backup that runs once a week

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet that I want to create a backup copy of the file once a week upon opening, for instance, when the spreadsheet is opened, the date of the last backup is checked and if the date it was created is more than 1 week ago, it will create a backup file.

This spreadsheet has a folder called Backups in the same folder it is in, which is where the backups are to be stored. The filename of the backup files are to be structured like this. Firstly, it needs the word Backup, then the name of the file that is being backed up, without the extension then it needs the date and time that it was backed up. The format for the last bit needs to be dd.mm.yy MMHH AM/PM, for instance "Backup Filename 24.3.21 129PM"

I found a very similar post that I posted a bit under a year ago but it was asking for a daily backup. I want a weekly backup now and I was not quite sure how to modify it. A lot of the other details are the same but any details in this post, takes precedence over details in that post I found.


I also want the ability to easily change the frequency of Backups. Possibly by having a cell that I can enter in weekly, fortnightly or monthly to set the frequency. This can be done on a sheet with the code name data, somewhere between A37:A50.

Could someone help me please?
 

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
I am trying to get the word backup before the original filename and I am getting the file not found error.

What is wrong with my line of code?
VBA Code:
ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\" & "Backup" & " " & fname & " " & dt & ".xlsm"
 
Upvote 0
Change this
Rich (BB code):
fpath & "\Backups\" & "Backup" & " " & fname & " " & dt & ".xlsm"

to
Rich (BB code):
fpath & "\Backups\Backup" & " " & fname & " " & dt & ".xlsm"
 
Upvote 0
I did that and I get this error
1616979354565.png


with the end if in the code highlighted.
 
Upvote 0
I restarted my computer, added the changes again and now it just highlighting this line saying it can't find the file
VBA Code:
    ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\Backup" & fname & " " & dt & ".xlsm"
 
Upvote 0
have you checkd to make sure fpath and fname are creating the correct variables ??
Ahh...needs a space after Backup
VBA Code:
 ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\Backup " & fname & " " & dt & ".xlsm"
 
Upvote 0
The sub works perfectly until I try to add the word Backup to the end of the directory, so

This works
VBA Code:
ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\" & fname & " " & dt & ".xlsm"


Whether I have a space after backups or not, still gives me the same error.


This
VBA Code:
ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\Backups" & fname & " " & dt & ".xlsm"
or
VBA Code:
ActiveWorkbook.SaveCopyAs FileName:=fpath & "\Backups\Backups " & fname & " " & dt & ".xlsm"
doesn't work. Gives me the can't find file error.
 
Upvote 0
The code works fine for me on my directories.
Shouldn't the 2nd Backups be without the "s", just "Backup "
 
Upvote 0
Is there another way of including the word Backup at the beginning of the filename?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

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