PDA

View Full Version : [SOLVED:] Help to create a back up workbook vba



VISHAL120
09-27-2011, 06:57 AM
Hi All.

I have the following code which am using to create a back up copy of my workbook:


Sub Create_Backup_Data()
Application.DisplayAlerts = False
ThisWorkbook.Activate
Wip_Workbook_Name = ThisWorkbook.Name
FileSystem.ChDir (ThisWorkbook.Path)
'ChDir "C:\Documents and Settings\My Documents\main\BKUP"
Current_Date = Format(Date, "dd mm yyyy")
Current_Time = Format(Time, "HH MM SS")
Bkup_Workbook_Name = "Bkup @ " & Current_Date & " - " & Current_Time & " _ " & ThisWorkbook.Name
ActiveWorkbook.SaveAs Filename:=Bkup_Wip_Workbook_Name
'ActiveWorkbook.SaveAs Filename:=Wip_Workbook_Name
Application.DisplayAlerts = True
End Sub

the problem is it save the back up on the same folder where the original file resides. i want it to be saved on another folder but since now i have not been able to do it.

i have tried to put different directory and folder but it saved my original file there.

thanks for the help.

Bob Phillips
09-27-2011, 07:25 AM
Specify the new path in the saveas (BTW, best to use SaveCopyAs not SaveAs, doesn't mess with Activeworkbook).



ActiveWorkbook.SaveCopyAs Filename:="C:\Documents and Settings\My Documents\main\BKUP\" & Bkup_Wip_Workbook_Name

VISHAL120
09-27-2011, 11:17 PM
Hi Bob,

Thanks i put it like this as with the previous it was still saving the copy on the original folder.

current_workbook_path = ""C:\Documents and Settings\\My Documents\MAIN\BKUP"

ActiveWorkbook.SaveCopyAs Filename:=current_workbook_path & Bkup_Factory_Wip_Workbook_Name

thanks again.

Norie
09-28-2011, 04:35 AM
You are missing the \ after the folder name BKUP which was in xld's code.

VISHAL120
09-28-2011, 04:37 AM
oh Yes . I forgot that.

thank you.