I'm trying to use Document.SaveAsCopy, but I am not getting the desired results. It seems to depend on the Range that I have chosen.
If I use this, specifying Selection for the Range:
1 2 3 4 5 6 7 8
Sub test_SaveAsCopy() Dim OptSave As New StructSaveAsOptions OptSave.Range = cdrSelection ActiveDocument.SaveAsCopy "D:\foo.cdr", OptSave End Sub
then it works as I would expect. A copy of the current document - but with only the selected objects - is created, but is not opened.
------------------------------------------------------------------------------------------
If I use this, specifying AllPages for the Range:
Sub test_SaveAsCopy() Dim OptSave As New StructSaveAsOptions OptSave.Range = cdrAllPages ActiveDocument.SaveAsCopy "D:\foo.cdr", OptSave End Sub
then it behaves as though I had performed a "Save As". The active document changes to be the just-created document. That is of course not what I want; I'm using SaveAsCopy because I just want to save a copy of the document and then continue editing the original document.
I see the same result if I use the SaveAsCopy without specifying any StructSaveAsOptions.
If I use this, specifying CurrentPage for the Range:
Sub test_SaveAsCopy() Dim OptSave As New StructSaveAsOptions OptSave.Range = cdrCurrentPage ActiveDocument.SaveAsCopy "D:\foo.cdr", OptSave End Sub
then I see this error:
Click on Debug, and it highlights the line:
ActiveDocument.SaveAsCopy "D:\foo.cdr", OptSave
Am I doing something wrong here? Can others confirm that SaveAsCopy is (or is not) working correctly for them?
Hi Eskimo,
Did you figure out what was going wrong with the SaveAsCopy method?
I know this thread is like 6 years ago! But looks like this problem still exists!
Suku
Hello Suku,
I never found a solution to that.
I did write a macro, but I didn't provide an option to use "cdrCurrentPage" for the range. Instead, my macro is limited to saving only the currently-selected objects.
The macro allows the user to specify a destination folder. After doing that, they have a "one click" way to save the current selection as a copy, in that folder, with no dialog (file name automatically created based on the parent file name plus a time stamp).
For some types of "destructive" things, (e.g., shaping operations), that can be a convenient way to save copies of intermediate steps in a multi-step process. Or, it can be used to quickly save different variations of a specific graphical asset, in a folder where they can be reviewed later.
How about a bit of a workaround to "OptSave.Range = cdrCurrentPage" I don't think this is supported, but:
Sub test_SaveCurrentPageAsCopy() Dim cdrDoc As Document Dim tempDoc As Document Dim page As Page Dim filePath As String ' Specify the file path for the saved document filePath = "D:\current_page_copy.cdr" ' Ensure there's an active document If Application.ActiveDocument Is Nothing Then MsgBox "There is no active document.", vbCritical Exit Sub End If ' Reference the active document and current page Set cdrDoc = Application.ActiveDocument Set page = cdrDoc.ActivePage ' Create a new temporary document Set tempDoc = Application.CreateDocument ' Copy all objects from the current page of the original document page.Shapes.All.Copy ' Paste the copied objects to the new document's active page tempDoc.ActiveLayer.Paste ' Save the temporary document as a copy and close it tempDoc.SaveAs filePath tempDoc.Close ' Inform the user MsgBox "Current page has been saved as " & filePath, vbInformationEnd Sub
Thanks for that info Eskimo.
My requirement was slightly different, needing to save the document as a copy and continue working on it or save a copy and work on the copy closing the original.
Implemented like this:
If IsCopy Then doc.SaveAsCopy fPath & fileName & ".cdr", opt 'save a copy and keep current doc openElse doc.SaveAs fPath & fileName & ".cdr", opt 'save a copy and open itEnd If
Of course because of SaveAsCopy not working as expected this code failed.
So had to save document, Save as a copy (which opened the copy and closed the original). If I wanted to work on the original, then had to close the copy and reopen the original. Kinda run around and crude, but had to make do with it.