Edit

Share via


TextRange.Expand method (Publisher)

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. Can be one of the PbTextUnit constants declared in the Microsoft Publisher type library.

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 method or the MoveEnd method.

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.

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 
 .Expand Unit:=pbTextUnitLine 
 .Font.Bold = msoTrue 
 End With 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.