Bookmark.StartOf(Object, Object) Method

Definition

Moves or extends the start position of the Bookmark control to the beginning of the nearest specified text unit.

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

Parameters

unit
Object

Microsoft.Office.Interop.Word.WdUnits. The unit by which the start position of the Bookmark control is to be moved.

Returns

The number of characters by which the Bookmark control was moved or extended. The method returns a negative number if the movement is backward through the document.

Examples

The following code example adds text to the first paragraph and then adds a Bookmark control with text to the second paragraph. The code then moves the start of the bookmark over one word.

This example is for a document-level customization.

private void BookmarkStartOf()
{
    object Unit = Word.WdUnits.wdWord;
    object Extend = Word.WdMovementType.wdExtend;
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "First paragraph of text.";
    this.Paragraphs[2].Range.Text = "Second paragraph of text.";
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[2].Range.Words[2],
        "bookmark1");
    
    bookmark1.StartOf(ref Unit, ref Extend);
}
Private Sub BookmarkStartOf()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "First paragraph of text."
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")

    Bookmark1.Text = "This is sample bookmark text."
    Bookmark1.StartOf(Word.WdUnits.wdWord, _
        Word.WdMovementType.wdMove)

End Sub

Remarks

If the beginning of the Bookmark control is already at the beginning of the specified 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