TextRange.Expand Method

Publisher Developer Reference

Expands the specified range or selection. Returns or sets a Long that represents the number of specified units added to the range or selection.

Syntax

expression.Expand(Unit)

expression   A variable that represents a TextRange object.

Parameters

Name Required/Optional Data Type Description
Unit Required PbTextUnit The unit by which to expand the range.

Return Value
Long

Remarks

The Expand method moves both endpoints of a range if necessary; to move only one endpoint of a range, use the MoveStart or MoveEnd method.

The Unit parameter can be one of the PbTextUnit constants declared in the Microsoft Office Publisher type library.

Example

This example creates a range that refers to the first word in the first shape of the active publication, formats the font for the word, and then it expands the range to reference the entire first paragraph and formats the font for the whole line.

Visual Basic for Applications
  Sub ExpandRange()
    Dim rngText As TextRange
Set rngText = ActiveDocument.Pages(1).Shapes(1) _
    .TextFrame.TextRange.Words(Start:=1, Length:=1)
With rngText
    With .Font
        .Size = 20
        .Italic = msoTrue
    End With
    .<strong>Expand</strong> Unit:=pbTextUnitLine
    .Font.Bold = msoTrue
End With

End Sub

See Also