我有以下代码,它构建了一个包含跟踪更改(标记)的MS单词页字符串。在循环结束时,我退出最后一页中包含轨道更改的位置。
然而,在最后一页没有轨道变化的地方,我陷入了循环(并非双关语)。在运行过程中,我收到一个确认框"你想启动文档的开头吗",它会循环
如何添加"exit-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
在使用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
,反之亦然)。