2013-07-05 20 views
0

我有以下代碼可以生成包含跟蹤更改(標記)的MS Word頁面的字符串。在循環結束時,我退出最後一頁包含軌跡變化的地方。VBS退出循環Word文檔中不存在更多跟蹤更改

但是,在最後一頁沒有跟蹤更改的情況下,我卡在循環中(沒有雙關語意圖)。在運行期間,我收到確認框'是否要開始文檔的開始',並且它會循環

如何添加'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 

回答

0

這是一個有點不清楚哪個版本的元素,你真的需要爲你使用WordBasic.NextChangeOrComment指令儘量跟蹤。

但是,假設你需要跟蹤修訂版,但沒有評論,你能不能把你的分評論後插入下面右邊的代碼:

'<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,反之亦然)。