次の方法で共有


Bookmark.GoToNext メソッド

次の項目の開始位置、または What 引数で指定された Bookmark コントロール内の位置を参照する Range オブジェクトを取得します。

名前空間:  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
次の項目の開始位置、または What 引数で指定された Bookmark コントロール内の位置を参照する Range オブジェクト。

解説

このメソッドに wdGoToGrammaticalErrorwdGoToProofreadingError、または 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 セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

Bookmark インターフェイス

Microsoft.Office.Tools.Word 名前空間