C# 跳转到第三条评论

C# 跳转到第三条评论,c#,office-interop,C#,Office Interop,如果存在使用Office Word Interop的Word文件,如何打开Word文件并自动跳转到该文件的第三条注释 我测试了Select方法,但需要跳转到该注释,而不是选择文本范围。Microsoft Word对象模型有一个集合。任何给定注释集合中的第三条注释可能是Comments(3)。(VBA集合是基于1的)。在VBA中,它类似于: If ActiveDocument.Comments.Count > 2 Then ActiveDocument.Comments(3).Sco

如果存在使用Office Word Interop的Word文件,如何打开Word文件并自动跳转到该文件的第三条注释


我测试了
Select
方法,但需要跳转到该注释,而不是选择文本范围。

Microsoft Word对象模型有一个集合。任何给定注释集合中的第三条注释可能是
Comments(3)
。(VBA集合是基于1的)。

在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);
    }
}
Scope是指向注释文本位置的Word.Range对象。
代码首先选择注释文本,然后将光标移到其开头。

文档对象有一个注释。你试过什么?你被困在哪里了?是的。我知道,但如何在打开文件后自动跳转到该注释?如何在打开文件后自动跳转到该注释?参见第17.5.1节。