Bookmark.Expand Method

Expands the Bookmark control.

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

Syntax

'Declaration
Function Expand ( _
    ByRef unit As Object _
) As Integer
int Expand(
    ref Object unit
)

Parameters

Return Value

Type: System.Int32
The number of characters added 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, 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 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
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); 
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace