Compartilhar via


Bookmark.MoveEnd Method

Moves the ending character position of a Bookmark control.

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

Syntax

'Declaration
Function MoveEnd ( _
    ByRef unit As Object, _
    ByRef count As Object _
) As Integer
int MoveEnd(
    ref Object unit,
    ref Object count
)

Parameters

  • unit
    Type: System.Object%

    The unit by which to move the ending character position.

  • count
    Type: System.Object%

    The number of units to move. If this number is positive, the ending character position is moved forward in the document. If this number is negative, the end is moved backward. If the ending position overtakes the starting position, the range collapses and both character positions move together. The default value is 1.

Return Value

Type: System.Int32
The number of units the Bookmark control actually moved, or it returns 0 (zero) if the move was unsuccessful.

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 and displays the last word of the bookmark in a message box. The code then calls the MoveEnd method and displays the last word of the bookmark in a new message box.

This example is for a document-level customization.

Private Sub BookmarkMoveEnd()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "This is sample text." 
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range.Words(3), _
        "Bookmark1")

    MessageBox.Show("Last word of bookmark prior to calling MoveEnd: " _
        & Bookmark1.Words.Last.Text)

    Bookmark1.MoveEnd(Word.WdUnits.wdWord, 1)

    MessageBox.Show("Last word of bookmark after calling MoveEnd: " _
        & Bookmark1.Words.Last.Text)
End Sub
private void BookmarkMoveEnd()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "This is sample text.";
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range.Words[3],
        "bookmark1");

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

    MessageBox.Show("Last word of bookmark prior to calling MoveEnd: "
        + bookmark1.Words.Last.Text);

    bookmark1.MoveEnd(ref Unit, ref Count);

    MessageBox.Show("Last word of bookmark after calling MoveEnd: "
        + bookmark1.Words.Last.Text);

}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace