共用方式為


Bookmark.EndOf(Object, Object) Method

Definition

Moves or extends the ending character position of a Bookmark control to the end of the nearest text unit.

public int EndOf (ref object unit, ref object extend);
abstract member EndOf : obj * obj -> int
Public Function EndOf (Optional ByRef unit As Object, Optional ByRef extend As Object) As Integer

Parameters

unit
Object

The unit by which to move the ending character position. Microsoft.Office.Interop.Word.WdUnits.

Returns

The number of character positions the Bookmark was extended.

Examples

The following code example adds a Bookmark control with text to the document and then adds additional text after the bookmark. It then extends the bookmark by one word.

This example is for a document-level customization.

private void BookmarkEndOf()
{
    object Unit = Word.WdUnits.wdWord;
    object Extend = Word.WdMovementType.wdMove;
    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.");
    bookmark1.EndOf(ref Unit, ref Extend);
}
Private Sub BookmarkEndOf()
    Dim Unit As Object = Word.WdUnits.wdWord
    Dim Extend As Object = Word.WdMovementType.wdMove
    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.")
    Bookmark1.EndOf(Unit, Extend)

End Sub

Remarks

If both the starting and ending positions for the Bookmark control are already at the end of the unit, this method does not move or extend the Bookmark control.

Optional Parameters

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

Applies to