Backing up Excel Files to a different Directory

Posted by Joe Taylor on Super User See other posts from Super User or by Joe Taylor
Published on 2010-05-14T12:37:03Z Indexed on 2010/05/14 12:44 UTC
Read the original article Hit count: 345

Filed under:
|

In Excel 2007 in the Save As box there is an option to 'Create a Backup' which simply backs up the file whenever it is saved. Unfortunately it backs up the file to the same directory as the original.
Is there a simple way to change this directory to another drive / folder? I have messed about with macros to do this, coming up with:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'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:="T:\TEC_SERV\Backup file folder - DO NOT DELETE\" & _ ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
End Sub

This creates a backup of the file ok the first time, however if this is tried again I get:
Run-Time Error '1004';
Microsoft Office Excel cannot access the file 'T:\TEC_SERV\Backup file folder - DO NOT DELETE\Test Macro Sheet.xlsm. There are several possible reasons:
The file name or path does not exist
The file is being used by another program
The workbook you are trying to save has the same name as a...

I know the path is correct, I also know that the file is not open anywhere else. The workbook has the same name as the one I'm trying to save over but it should just overwrite.

I have posted the question about the coding on Stack Overflow but wondered if there is an easier way to do this.

Any help would be much appreciated. Joe

© Super User or respective owner

Related posts about excel-2007

Related posts about macros