Word SaveCopyAs

Discussion in 'Word VBA' started by Michael Sundermann, Jan 27, 2004.

  1. Hi,

    Excel and PowerPoint have a SaveCopyAs method

    Word does not have such a function.
    Does anyone know how so simulate such a function in Word ?

    My best idea is the code below.

    The below code compares the memory image of the active document
    with the file it is associated with.
    The compare results are placed in a new file.
    Any changes in the resulting new file are accepted
    and the results written to the temp file.


    Public Sub Test()

    Dim TempName As String
    Dim OrigName As String

    TempName = "C:\temp\" & ActiveDocument.Name
    OrigName = ActiveDocument.FullName

    Name:=OrigName, CompareTarget:=wdCompareTargetNew
    'the new document is now active
    If ActiveDocument.Revisions.Count >= 1 Then _
    ActiveDocument.SaveAs FileName:=TempName

    End Sub
    Michael Sundermann, Jan 27, 2004
    1. Advertisements

  2. Hi Michael,


    Dim SourceFile, DestinationFile
    SourceFile = ActiveDocument.Name ' Define source file name.
    DestinationFile = "C:\Temp\" & SourceFile ' Define target file name.
    FileCopy SourceFile, DestinationFile ' Copy source to target
    Documents.Open SourceFile

    Please post any further questions or followup to the newsgroups for the
    benefit of others who may be interested. Unsolicited questions forwarded
    directly to me will only be answered on a paid consulting basis.
    Hope this helps
    Doug Robbins - Word MVP
    Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT, Jan 27, 2004
    1. Advertisements

  3. On Wed, 28 Jan 2004 00:04:41 +1000, "Doug Robbins - Word MVP - DELETE

    Thanks for your solution,
    but it does not simulate SaveCopyAs.

    The important thing is that SaveCopyAs
    saves the active document to a different file
    _without_ saving the active document.
    Michael Sundermann, Jan 28, 2004
  4. Michael Sundermann

    JGM Guest

    Hi Michael,
    Sorry, but how is that different from the SaveAs method? Unless io totally
    missed your point, it seems to me that Word already offers what you need.

    "Save as" does exactly that: save the active document as a new document
    without saving the changes in that active document.

    Try it:
    Create a new document;
    Type "Test 1";
    Save it, call it "Test 1.doc";
    Now, hit ENTER;
    Type "Test 2";
    From the "File" menu, select "Save as" (not save);
    Call it "Test 2.doc";
    Close Word;
    Open "Test 1.doc";
    See that it contains only "Test 1";
    Open "Test 2.doc";
    See that it contains "Test1"¶ "Test 2";

    Isn't this what you are looking for?

    JGM, Jan 28, 2004
  5. Sorry, but how is that different from the SaveAs method? Unless io totally
    Using the SaveAs(file) method changes the active document to "file".

    Excel and Powerpoint have both methods: SaveAs and SaveCopyAs.
    With SaveCopyAs you can save the active document to a file
    and nothing else happens.
    Michael Sundermann, Jan 29, 2004
  6. Thanks for this solution.
    This solution has 2 disadvantages:
    The user gets a "flash", because Word closes and opens
    the document.
    I want to use such a function in an Add-On,
    probably many users thinks my AddOn has an error
    if they got such a flash.

    The solution only works if the Document was saved before.
    If not, Sourcename is like "Document" and Word reports
    an error. But this could be repaired:

    If Sourcename does not exists
    create a tremporay name

    At the moment I only care about the flash.
    But with my solution I also get such a flash.
    Michael Sundermann, Jan 29, 2004
  7. Michael Sundermann


    Dec 12, 2018
    Likes Received:

    even if this thread is quite old. I searched long time for a solution and finally could establish one.
    Maybe someone else is also searching and steps over this thread.
    I implemented the following solution which works fine:

    ' Saves a copy of the document
    ' This macro doesn´t change anything on the original document.
    ' Even unsaved changes stay unchanged.
    ' The copy stays open
    Dim DocumentOld As Document
    Dim DocumentNew As Document

    Application.ScreenUpdating = False

    ' Original document
    Set DocumentOld = ActiveDocument

    ' Open a new empty document for compare
    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
    Set DocumentNew = ActiveDocument

    ' Create a new document in which all differences of the original document to the empty document are reported
    ' and all differences will be accepted
    Application.CompareDocuments _
    OriginalDocument:=DocumentNew, _
    ' Finally close the views that were necessary for the comparison
    ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsNone

    ' Save comparison results under the name of the copy document
    ActiveDocument.SaveAs2 FileName:=NewFileName

    ' and close the empty one

    Application.ScreenUpdating = True
    End Sub

    Good luck,
    Uli2000, Dec 12, 2018
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.