Bookmark.Next(Object, Object) Method

Definition

Gets a Range object that represents the specified unit relative to the Bookmark control.

public Microsoft.Office.Interop.Word.Range Next (ref object Unit, ref object Count);
abstract member Next : obj * obj -> Microsoft.Office.Interop.Word.Range
Public Function Next (Optional ByRef Unit As Object, Optional ByRef Count As Object) As Range

Parameters

Unit
Object

The type of units by which to count. Can be any Microsoft.Office.Interop.Word.WdUnits constant.

Count
Object

The number of units by which you want to move ahead. The default value is one.

Returns

A Range object that represents the specified unit relative to the Bookmark control.

Examples

The following code example adds a Bookmark control with text to the first paragraph, inserts additional text after the bookmark, and then displays the next word after the bookmark in a message box.

This example is for a document-level customization.

private void BookmarkNext()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "This is sample bookmark text.";
    bookmark1.InsertAfter (" This text is inserted after the bookmark.");

    object Unit = Word.WdUnits.wdWord;
    object Count = 1;

    Word.Range range1 = bookmark1.Next(ref Unit, ref Count);

    MessageBox.Show("The next word after Bookmark1 is at " +	
        "position " + range1.Start + " through " + range1.End);
}
Private Sub BookmarkNext()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    Bookmark1.Text = "This is sample bookmark text."
    Bookmark1.InsertAfter(" This text is inserted after " & _
        "the bookmark.")

    Dim Range1 As Word.Range = Bookmark1.Next( _
        Word.WdUnits.wdWord, 1)

    MessageBox.Show("The next word after Bookmark1 is at " & _
        "position " & Range1.Start.ToString & " through " & _
        Range1.End.ToString)

End Sub

Remarks

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to