TextFrame Object
Description
Represents the text frame in a Shape object. Contains the text in the text frame as well as the properties that control the margins and orientation of the text frame.
Using the TextFrame Object
Use the TextFrame property to return the TextFrame object for a shape. The TextRange property returns a Range object that represents the range of text inside the specified text frame. The following example adds text to the text frame of shape one in the active document.
ActiveDocument.Shapes(1).TextFrame.TextRange.Text = "My Text"
Note Some shapes don't support attached text (lines, freeforms, pictures, and OLE objects, for example). If you attempt to return or set properties that control text in a text frame for those objects, an error occurs.
Use the HasText property to determine whether the text frame contains text, as shown in the following example.
For Each s In ActiveDocument.Shapes
With s.TextFrame
If .HasText Then MsgBox .TextRange.Text
End With
Next
Text frames can be linked together so that the text flows from the text frame of one shape into the text frame of another shape. Use the Next and Previous properties to link text frames. The following example creates a text box (a rectangle with a text frame) and adds some text to it. It then creates another text box and links the two text frames together so that the text flows from the first text frame into the second one.
Set myTB1 = ActiveDocument.Shapes.AddTextbox _
(msoTextOrientationHorizontal, 72, 72, 72, 36)
myTB1.TextFrame.TextRange = "This is some text. This is some more text."
Set myTB2 = ActiveDocument.Shapes.AddTextbox _
(msoTextOrientationHorizontal, 72, 144, 72, 36)
myTB1.TextFrame.Next = myTB2.TextFrame
Use the ContainingRange property to return a Range object that represents the entire story that flows between linked text frames. The following example checks the spelling in the text in TextBox 3 and any other text that's linked to TextBox 3.
Set myStory = ActiveDocument.Shapes("TextBox 3") _
.TextFrame.ContainingRange
myStory.CheckSpelling
Properties
Application property, ContainingRange property, Creator property, HasText property, MarginBottom property, MarginLeft property, MarginRight property, MarginTop property, Next property, Orientation property, Overflowing property, Parent property, Previous property, TextRange property.
Methods
BreakForwardLink method, ValidLinkTarget method.
See Also
AddLabel method, AddTextbox method, CreateTextbox method, Frame object.