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