Udostępnij za pośrednictwem


Bookmark.Expand(Object) Method

Definition

Expands the Bookmark control.

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

Parameters

unit
Object

The unit by which to expand the range of the Bookmark control. Microsoft.Office.Interop.Word.WdUnits.

Returns

The number of characters added to the Bookmark control.

Examples

The following code example adds a Bookmark control with text to the first paragraph, then inserts a sentence after the bookmark and extends the bookmark to include the new sentence.

This example is for a document-level customization.

private void BookmarkExpand()
{
    object unit = Word.WdUnits.wdSentence;
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "This is sample ";
    bookmark1.InsertAfter("bookmark text. This is text "
                    + "inserted after the bookmark. ");
    bookmark1.Expand(ref unit);	
}
Private Sub BookmarkExpand()
    Dim unit As Object = Word.WdUnits.wdSentence
    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 "
    Bookmark1.InsertAfter("bookmark text. This is text inserted" _
       & " after the bookmark.")
    Bookmark1.Expand(unit)

End Sub

Remarks

Optional Parameters

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

Applies to