Share via


TextRange Property

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns a TextRange object that represents the text that's attached to a shape, as well as properties and methods for manipulating the text.

expression.TextRange

expression   Required. An expression that returns one of the objects in the Applies To list.

Example

The following example adds text to the text frame of shape one in the active publication, and then formats the new text. This example assumes there is at least one shape on the first page of the active publication.

  Sub AddTextToTextFrame()
    With ActiveDocument.Pages(1).Shapes(1).TextFrame.TextRange
        .Text = "My Text"
        With .Font
            .Bold = msoTrue
            .Size = 25
            .Name = "Algerian"
        End With
    End With
End Sub

The following example adds a rectangle to the active publication and adds text to it.

  Sub AddTextToShape()
    With ActiveDocument.Pages(1).Shapes.AddShape(Type:=msoShapeRectangle, _
        Left:=72, Top:=72, Width:=250, Height:=140)
        .TextFrame.TextRange.Text = "Here is some test text"
    End With
End Sub