PDA

View Full Version : Copying changed pages from one document to new one



chrscote
11-14-2017, 11:00 AM
I have a document which has Track Changes turned on and contains a number of revisions. I am trying to create a script that will take the contents of a page that has a revision and copy it to a new document so that the new document will contain only those pages that have changed. Unfortunately, in the script I have written now, the code selects the first page for copying every time through the loop. Here is the code I have so far:

For Each oRevision In oDoc.Revisions
oDoc.Activate
revNum = revNum + 1
'If this page hasn't already been copied (for multiple revisions on single page)
If oRevision.Range.Information(wdActiveEndPageNumber) <> nLastPageNum Then
'Also check that the change is not in the header or footer
If oRevision.Range.StoryType = wdMainTextStory Then
MsgBox (oRevision.Range.Text)
'Add 1 to counter
n = n + 1
ActiveDocument.Bookmarks("\Page").Select
Selection.Copy
oNewDoc.Activate
Selection.EndKey wdStory
Selection.InsertBreak (wdPageBreak)
Selection.PasteAndFormat wdPasteDefault
nLastPageNum = oRevision.Range.Information(wdActiveEndPageNumber)
End If
End If
Next oRevision
I'm sure the 2nd part (pasting) is working fine, but the first portion where I select the page keeps selecting the first page rather than the page that has the change. Any help would be greatly appreciated.

Chris

macropod
11-14-2017, 04:17 PM
Cross-posted (and answered) at: http://www.msofficeforums.com/word-vba/37346-copying-pasting-pages-changes.html
Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3