2014-02-18 34 views
0

如果存在使用Office Word-Interop,如何打開一個Word文件並自動跳轉到該文件的第三條評論?跳轉到第三個評論

我被測試Select方法,但需要跳轉到該評論,而不是選擇文本範圍。

+0

Document對象具有[註釋屬性](http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.comments(v = office.14).aspx) 。你有什麼嘗試?你卡在哪裏? – Heinzi

+0

是的。我知道,但如何打開文件後自動跳轉到該評論? – ARZ

回答

0

Microsoft Word對象模型有一個Comments集合。任何給定評論集合中的第三條評論可能是Comments(3)。 (VBA集合是基於1的)。

+0

如何在打開文件後自動跳轉到該評論? – ARZ

+0

請參閱第17.5.1節[這裏](http://msdn.microsoft.com/en-us/library/office/dd492012(v = office.12).aspx)。 –

0

在VBA它會是這樣的:

If ActiveDocument.Comments.Count > 2 Then 
    ActiveDocument.Comments(3).Scope.Select 
    Application.Selection.StartOf (Word.WdUnits.wdColumn) 
End If 

在插件的C#項目非常相似:

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{ 
    this.Application.DocumentChange += new Word.ApplicationEvents4_DocumentChangeEventHandler(Application_DocumentChange); 

}   

void Application_DocumentChange() 
{ 
    if (this.Application.ActiveDocument.Comments.Count > 2 /* && code to check if its first document opening or changing documents */) 
    { 
     object unit = Word.WdUnits.wdColumn; 
     object missing = Type.Missing; 

     this.Application.ActiveDocument.Comments[3].Scope.Select(); 
     this.Application.Selection.StartOf(ref unit, ref missing); 
    } 
} 

Comment.Scope是Word.Range對象指向評論位置文本。 代碼首先選擇註釋文本,然後將光標移動到其開頭。