0

我有以下代码构建一串包含跟踪更改(标记)的 MS word 页面。在循环结束时,我退出最后一页包含跟踪更改的位置。

但是,在最后一页没有音轨变化的地方,我陷入了一个循环(没有双关语)。在运行过程中,我得到确认框'你想从文档的开头开始',它会循环

如何添加“退出 do”,以便在找到最后一个轨道更改的位置(不是在最后一页上)退出 do 语句?

    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
4

1 回答 1

0

WordBasic.NextChangeOrComment就您使用指令而言,您真正需要跟踪哪些修订元素有点不清楚。

但是,假设您需要跟踪修订而不是评论,您可以在您对 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

如果您需要跟踪评论,您需要创建与修订项目类似的解决方案(Comments collection不包括Revisions collection,反之亦然)。

于 2013-07-05T06:29:51.550 回答