Partager via


Bookmark.Next Method

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

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function Next ( _
    ByRef Unit As Object, _
    ByRef Count As Object _
) As Range
Range Next(
    ref Object Unit,
    ref Object Count
)

Parameters

  • Count
    Type: System.Object%

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

Return Value

Type: Microsoft.Office.Interop.Word.Range
A Range object that represents the specified unit relative to the Bookmark control.

Remarks

Optional Parameters

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

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 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
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);
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace