Bookmark.GoToNext 方法
取得 Range 物件,此物件參考至下一個項目的起始位置,或由 What 引數所指定在 Bookmark 控制項中的位置。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)
語法
'宣告
Function GoToNext ( _
What As WdGoToItem _
) As Range
Range GoToNext(
WdGoToItem What
)
參數
傳回值
型別:Microsoft.Office.Interop.Word.Range
Range 物件,此物件參考至下一個項目的起始位置,或由 What 引數所指定在 Bookmark 控制項中的位置。
備註
當您將這個方法和 wdGoToGrammaticalError、wdGoToProofreadingError,或 wdGoToSpellingError 常數搭配使用時,所傳回的 Range 物件會包含任何文法錯誤文字或拼字錯誤文字。
範例
下列程式碼範例會將文字以及有文字的 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。