Bookmark.Collapse Method

Collapses a Bookmark control to the starting or ending position.

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

Syntax

'Declaration
Sub Collapse ( _
    ByRef direction As Object _
)
void Collapse(
    ref Object direction
)

Parameters

Remarks

After a Bookmark control is collapsed, the starting and ending points are equal.

If you use wdCollapseEnd to collapse a Bookmark control that refers to an entire paragraph, the range is located after the ending paragraph mark (the beginning of the next paragraph). However, you can move the range back one character by using the MoveEnd method after the range of the Bookmark control is collapsed.

Optional Parameters

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

Examples

The following code example adds a Bookmark control with text, and then displays the start and end position of the bookmark before and after collapsing the bookmark.

This example is for a document-level customization.

Private Sub BookmarkCollapse()

    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."
    MessageBox.Show("Start and end of Bookmark1 before calling Collapse: " _
        & Bookmark1.Start.ToString() & " and " & Bookmark1.End.ToString)

    Dim Direction As Object = Word.WdCollapseDirection.wdCollapseEnd
    Bookmark1.Collapse(Direction)

    MessageBox.Show("Start and end of Bookmark1 after calling Collapse: " _
        & Bookmark1.Start.ToString() & " and " & Bookmark1.End.ToString)

End Sub
private void BookmarkCollapse()
{
    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.";
    MessageBox.Show("Start and end of bookmark1 before calling Collapse: " +
        bookmark1.Start.ToString() + " and " + bookmark1.End.ToString());

    object Direction = Word.WdCollapseDirection.wdCollapseEnd;
    bookmark1.Collapse(ref Direction);

    MessageBox.Show("Start and end of bookmark1 after calling Collapse: " +
        bookmark1.Start.ToString() + " and " + bookmark1.End.ToString());
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace