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?
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