PDA

View Full Version : Backup workbook before modifying



cdbrown
07-11-2006, 06:16 AM
Hi all,
I would like some code that when a user selects a workbook to modify, makes a backup copy of the unmodified wb in a different folder (..Output\Backup\). The user can then modify the wb and it get's saved in it's original location.


Private Sub CommandButton2_Click()
Public SFolder, OpFolder, MyFolder, Fname
Dim wb1, wb2 As Workbook

SFolder = Sheets("List").Cells(7, 6) 'folder to save or copy the backup to
OpFolder = Sheets("List").Cells(1, 6) & "\" 'folder containing the wbs to modify

Set wb1 = ThisWorkbook
ChDir OpFolder
Fname = Application.GetOpenFilename("Excel-files,*.xls", , "Please select the output you wish to modify")
Workbooks.Open Filename:=Fname


I'm not sure if I should be opening the file, then saving the backup or should it copy it before opening.

Again - any help would be much appreciated.

Regards
-cdbrown

OBP
07-11-2006, 07:13 AM
Personally I would open the Workbook and in the Workbook's Open event procedure save the file to the "backup" folder with a new name by adding the Date (formatted to remove the "/") to the current name.
In that way you can see when the workbook was used and have more than one backup.
If the workbook is to be used more than once per day you could add the correctly formatted time to the name or an incrementing value stored in a cell on theworkbook.

cdbrown
07-11-2006, 07:34 AM
Thanks for that - but a bit more information on my part may have helped. The workbook (wb2) I want to backup then modify is created (along with about 400 other workbooks) by modelling software and does not contain any macros - just a pure data dump which I then manipulate by other workbooks. I only want to make a backup of the original wb2 if I need to change the data in some way and am not worried about recording any further changes. This has then made me think that if the backup already exists in SFolder I don't want to over write it if someone has decided to make further changes to wb2. Ideally wb2 will only be modified once to correct the inaccuracies of the modelling software.

Hope this makes more sense.

Cheers
-cdbrown