PDA

View Full Version : how to save a backup file



NFS79
01-13-2013, 08:26 AM
Hi, please forgive me if there is an easy way to do this but I'm new to VBA, trying to teach myself as I need it...

I've got a file "Quality and Productivity metric data.xlsm" that I have written a macro to push specific data to other sheets as needed. it's quite involved (or it is for me) and while it seems to run fine, there will be other users working with my workbook as well.

what I'd like to do as a first step of my macro is to save a backup of my master file before the macro does anything.

the idea being that if the macro fails catasrophically then I can easily go back to where i was...

I'd like to keep this backup in the same location as the original, and I would like to replace the backup file when the macro is run again - I only need to keep the latest file, no need to keep a bunch of revisions.

can anyone help with this? thanks to everyone on this site, I've gotten a lot of information from reading others posts!

rrosa1
01-13-2013, 09:05 AM
used this code in the end of yr macro and change the dir as u desired


MyDate = Date
MyMonth = Month(MyDate)
ThisWorkbook.SaveAs Filename:="C:\backup\" & MonthName(MyMonth) & "-" & Day(Date) & "-" & ThisWorkbook.Name


hope it's help

NFS79
01-13-2013, 09:52 AM
used this code in the end of yr macro and change the dir as u desired


MyDate = Date
MyMonth = Month(MyDate)
ThisWorkbook.SaveAs Filename:="C:\backup\" & MonthName(MyMonth) & "-" & Day(Date) & "-" & ThisWorkbook.Name


hope it's help

Thank you! will this save a new file for every date? I'd like to just keep 1 backup file. I'd like to overwrite the backup file each time I run the macro

rrosa1
01-13-2013, 10:13 AM
just used

ThisWorkbook.SaveAs Filename:="C:\backup\"BackUp-" & ThisWorkbook.Name

NFS79
01-14-2013, 08:18 AM
just used

ThisWorkbook.SaveAs Filename:="C:\backup\"BackUp-" & ThisWorkbook.Name

perfect thank you very much!

rrosa1
01-14-2013, 02:53 PM
NFS79 can u pl mark the post as " solved "