Word SaveCopyAs


M

Michael Sundermann

Hi,

Excel and PowerPoint have a SaveCopyAs method
(Workbook/Presentation).

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.

Thanks
Michael




Public Sub Test()

Dim TempName As String
Dim OrigName As String

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

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

End Sub
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Michael,

Use

Dim SourceFile, DestinationFile
ActiveDocument.Save
SourceFile = ActiveDocument.Name ' Define source file name.
DestinationFile = "C:\Temp\" & SourceFile ' Define target file name.
ActiveDocument.Close
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
 
Ad

Advertisements

M

Michael Sundermann

On Wed, 28 Jan 2004 00:04:41 +1000, "Doug Robbins - Word MVP - DELETE
UPPERCASE CHARACTERS FROM EMAIL ADDRESS"

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.
 
J

JGM

Hi Michael,
The important thing is that SaveCopyAs
saves the active document to a different file
_without_ saving the active document.
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?

Cheers!
 
M

Michael Sundermann

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.
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.
 
M

Michael Sundermann

Dim SourceFile
SourceFile = ActiveDocument.FullName ' Define source file name.
ActiveDocument.SaveAs
ActiveDocument.Close
Documents.Open SourceFile
Thanks for this solution.
This solution has 2 disadvantages:
1.
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.

2.
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
endif



At the moment I only care about the flash.
But with my solution I also get such a flash.
 
Ad

Advertisements

Joined
Dec 12, 2018
Messages
1
Reaction score
0
Hi,

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, _
RevisedDocument:=DocumentOld
Selection.WholeStory
Selection.Range.Revisions.AcceptAll
' 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
DocumentNew.Close

Application.ScreenUpdating = True
End Sub

Good luck,
Uli
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top