Results 1 to 2 of 2

Thread: Copying changed pages to new document

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    2

    Exclamation Copying changed pages to new document

    I have a document which has Track Changes turned on and contains some revisions. I am trying to have the pages that contain revisions copied to a 2nd document so that the new doc will contain only the pages that have changed. The problem I'm having is that each time through the loop, the code is selecting the first page instead of the page with the change. Here is the code as it stands right now:
    Code:
    For Each oRevision In oDoc.Revisions
            revNum = revNum + 1
            oDoc.Activate
            '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
    The message box is displaying the proper text, but when I get to the Select statement, it keeps selecting the first page instead. What am I doing wrong? Any help would be greatly appreciated.

    Chris

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Copying changed pages to new document

    Not sure what the lines below are supposed to be doing:

    'Add 1 to counter
    n = n + 1

    However, the line below is probably selecting the same text every time:

    ActiveDocument.Bookmarks("\Page").Select

    What you want is to select the text on the page with the revision range. You need the correct page number for that.

    Maybe something like:

    Selection.Information(wdActiveEndPageNumber)

    Possibly useful links:

    https://social.msdn.microsoft.com/Fo...d?forum=isvvba

    https://stackoverflow.com/questions/...ext-from-array

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width