使用 Document 类的 Comments 属性可以向 Microsoft Office Word 文档中的文本范围添加注释。
**适用于:**本主题中的信息适用于 Word 2007 和 Word 2010 的文档级项目和应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能。
下面的示例向文档中的第一个段落添加注释。
向文档级自定义项中的文本添加新注释
调用 Comments 属性的 Add 方法,并提供一个范围和相应的注释文本。 若要使用下面的代码示例,请从项目内的 ThisDocument 类中运行此示例。
Me.Comments.Add(Me.Paragraphs(1).Range, "Add a comment to the first paragraph.")
object text = "Add a comment to the first paragraph."; this.Comments.Add(this.Paragraphs[1].Range, ref text);
向应用程序级外接程序中的文本添加新注释
调用 Comments 属性的 Add 方法,并提供一个范围和相应的注释文本。
下面的代码示例向活动文档添加注释。 若要使用此示例,请从项目内的 ThisAddIn 类中运行此示例。
Me.Application.ActiveDocument.Comments.Add( _ Me.Application.ActiveDocument.Paragraphs(1).Range, _ "Add a comment to the first paragraph.")
object text = "Add a comment to the first paragraph."; this.Application.ActiveDocument.Comments.Add( this.Application.ActiveDocument.Paragraphs[1].Range, ref text);
可靠编程
若要更改 Word 添加到注释的用户姓名缩写,请使用 UserInitials 属性。