Is there a way to save a copy of a workbook in VBA?

TomCon

Active Member
Joined
Mar 31, 2011
Messages
385
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
If you do a "Save As" the workbook you are working in is not left open, instead what is left open is the new workbook with the new name. What I'd like is for the original workbook to remain open, but that a copy of it is tucked off somewhere. In fact i don't really want that copy open at all, just saved under that name.

Is there a way to do that?

Also wondering if you are in the middle of executing VBA and do a "Save As" does the code continue executing at the same place in the new-named workbook? Or is there any discontinuity/interruption?

Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
TomCon, try SaveCopyAs

Code:
ActiveWorkbook.SaveCopyAs "complete path & file name"
 
Last edited:
Upvote 0
Thanks much! I didn't know about SaveCopyAs, so thats what i need!

I do have a follow-up question. Do you know how to specify the path to save a file to OneDrive?

When i recorded a macro, this was recorded:
ActiveWorkbook.SaveAs Filename:= _
"https://d.docs.live.net/da6e7d8e7901482d/D4_p_TRK.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Of course i did not specify the whole "d.docs.live..." thing. Using the UI, I just selected OneDrive and then my file name, "D4_p_TRK.xlsm" and that was what was recorded by the macro recorder.

But, when i tried this in a macro:
ActiveWorkbook.SaveCopyAs "https://d.docs.live.net/da6e7d8e7901482d/D4_p_TRK.xlsm"

I got the following error:
Error 1004
Sorry, we couldn't find "https://d.docs.live...". Is it possible it was moved, renamed, or deleted.

The error message seems mysterious as this is a save operation, not an open operation.

So...can somebody tell me what to put in the "" with SaveCopyAs to save a copy of the file to OneDrive?

Thanks!
 
Upvote 0
You are welcome ... I have never tried to save some a document directly to google drive through VBA. But if you do record the same macro couple more times, would it still give the same link ? Have you tried to google this ?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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