Bookmark.GoToPrevious 方法
获取一个 Range 对象,该对象表示由 What 参数指定的 Bookmark 控件中上一项或位置的起始位置。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)
语法
声明
Function GoToPrevious ( _
What As WdGoToItem _
) As Range
Range GoToPrevious(
WdGoToItem What
)
参数
- What
类型:Microsoft.Office.Interop.Word.WdGoToItem
WdGoToItem.要移动到 Bookmark 控件中的项。
返回值
类型:Microsoft.Office.Interop.Word.Range
一个 Range 对象,表示由 What 参数指定的 Bookmark 控件中上一项或位置的起始位置。
示例
下面的代码示例向文档中添加文本和一个带有文本的 Bookmark 控件,然后为该文本添加注释。 此代码示例使用 GoToNext 和 GoToPrevious 在消息框中显示注释的位置。
此示例针对的是文档级自定义项。
Private Sub BookmarkGoToNext()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Text = "This is the first paragraph."
Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
Me.Controls.AddBookmark(Me.Paragraphs(2).Range, "Bookmark1")
Bookmark1.Text = "This is original text of the bookmark."
Dim commentText As Object = "This is some comment text."
Me.Paragraphs(1).Range.Comments.Add(Me.Paragraphs(1).Range _
.Words(4), commentText)
Bookmark1.Words.First.Comments.Add(Bookmark1.Words.First, _
commentText)
Bookmark1.InsertBefore("Text inserted before bookmark. ")
Bookmark1.InsertAfter(" Text inserted after bookmark.")
Dim range1 As Word.Range = Bookmark1.GoToNext( _
Word.WdGoToItem.wdGoToComment)
Dim range2 As Word.Range = Bookmark1.GoToPrevious( _
Word.WdGoToItem.wdGoToComment)
MessageBox.Show("Using GoToNext, the comment is " & _
"at position " & range1.Start.ToString & vbLf & _
"Using GoToPrevious, the comment is at position " & _
range2.Start.ToString)
End Sub
private void BookmarkGoToNext()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Text = "This is the first paragraph.";
Microsoft.Office.Tools.Word.Bookmark bookmark1 =
this.Controls.AddBookmark(this.Paragraphs[2].Range,
"bookmark1");
bookmark1.Text = "This is original text of the bookmark.";
object commentText = "This is some comment text.";
this.Paragraphs[1].Range.Comments.Add(this.Paragraphs[1]
.Range.Words[4], ref commentText);
bookmark1.Words.First.Comments.Add(bookmark1.Words.First,
ref commentText);
bookmark1.InsertBefore("Text inserted before bookmark. ");
bookmark1.InsertAfter(" Text inserted after bookmark.");
Word.Range range1 = bookmark1.GoToNext(Word.WdGoToItem.wdGoToComment);
Word.Range range2 = bookmark1.GoToPrevious(Word.WdGoToItem.wdGoToComment);
MessageBox.Show("Using GoToNext, the comment is at position "
+ range1.Start.ToString() + "\n" +
"Using GoToPrevious, the comment is at position "
+ range2.Start.ToString());
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。