How to swap the contents of a document with contents from another

B

Bug Repro

Hello

I am creating a solution in which I need to swap the contents of an existing
document with contents from a backup copy. The user experience should be as
smooth as possible. Ideally the view state etc of the original document being
will be preserved (for example what page the user was on, zoom etc.)

The original document is in open state before this operation starts. What I
am thinking of is to copy and past of all the content from one document to
another, and then saving the destination document. Is there a better option
which doesn't require closing the destination document, and then re-opening
it?

I need to do this for Word 2003 and 2007.
 
D

Doug Robbins - Word MVP

The following will do what you want other than maintain the cursor position.

Dim source As Document, target As Document
Set target = ActiveDocument
With Dialogs(wdDialogFileOpen)
If .Show Then
Set source = ActiveDocument
Else
MsgBox "Cancelled by user."
Exit Sub
End If
End With
target.Activate
target.Range.FormattedText = source.Range.FormattedText


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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

Top