0
votes

I have the following code that builds a string of MS word pages that contain track changes (markup). At the end of the loop I exit where track changes are contained on the last page.

However where there are no track changes on the last page I am stuck in a loop (no pun intended). During the run I get the confirmation box 'do you want to start the the beginning of the document' and it loops

How can I add an 'exit do', so where the last track changes are found (not on the last page) the do statement is exited?

    Sub finaltest()
      Dim CurPage As Integer      
      Dim totalPages As Integer
      Dim Pages As String

    'declare variables
      Pages = ""

      'total page count
      ActiveDocument.Repaginate
      totalPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

      'get us home
      Selection.HomeKey Unit:=wdStory


      Do
        'find next change
        WordBasic.NextChangeOrComment

        'get current page
        CurPage = Selection.Information(wdActiveEndAdjustedPageNumber)
        Pages = Pages & ", " & CurPage


        '<exit loop if there is no more track changes and not at last page>


      Loop Until CurPage = totalPages
      Pages = Right(Pages, Len(Pages) - 2)
      MsgBox Pages
    End Sub
1

1 Answers

0
votes

It is a bit unclear which revision elements you really need to track as far as you use WordBasic.NextChangeOrComment instruction.

However, assuming that you need to track revisions but not comments you could insert the code below right after the comment you put to your Sub:

'<exit loop if there is no more track changes and not at last page>
With ActiveDocument.Content.Revisions
    If Selection.Range = .Item(.Count).Range Then

        'MsgBox "Last one" - for test only
        Exit Do

    End If
End With

If you need to trace comments to you need to create similar solution as for revision items (Comments collection doesn't include Revisions collection and vice-versa).