Save a copy of a workbook when saving active version

sethness15

New Member
Joined
Dec 11, 2013
Messages
4
Hi All,

I think I'm going about this right but there's just something slightly wrong with my code.. I'm trying to have excel save a copy of my workbook to a specific directory when the active file is saved. Here's what I have..


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SaveAs Filename:="C:\Users\me\Desktop\Copy.xls", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub


It's saving the file but excel stops working afterwards.

Please let me know if you have any suggestions.

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
try using SaveCopyAs method:

Code:
ActiveWorkbook.SaveCopyAs "C:\Users\me\Desktop\Copy.xls"

Dave
 
Upvote 0
Hi Dave,

Still having the same issue where excel stops working. It seems to work the first time I save but gets screwed up when the copy already exists and I make a change to the original file and try to save.. Once I get it working, I'd like to make the message about the copy already existing to not pop up. (I want to automatically save over it.)

This is my code now:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="C:\Users\me\Desktop\Copy.xlsm"

End Sub

Thanks,
Seth

Hi,
try using SaveCopyAs method:

Code:
ActiveWorkbook.SaveCopyAs "C:\Users\me\Desktop\Copy.xls"

Dave
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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