Class TextFrame (Excel VBA)

The class TextFrame represents the text frame in a Shape object. Contains the text in the text frame as well as the properties and methods that control the alignment and anchoring of the text frame.

Methods

Other Methods

Characters - Returns a Characters object that represents a range of characters within a shape's text frame. You can use the Characters object to add and format characters within the text frame.

With ActiveSheet.Shapes(1).TextFrame 
 .Characters.Text = "abcdefg" 
 .Characters(3, 1).Font.Bold = True 
End With

Properties

AutoMargins returns or sets whether Excel automatically calculates text frame margins.

AutoSize true if the size of the specified object is changed automatically to fit text within its boundaries.

Worksheets(1).Shapes(1).TextFrame.AutoSize = True

HorizontalAlignment returns or sets an XlHAlign value that represents the horizontal alignment for the specified object.

HorizontalOverflow returns or sets the horizontal overflow setting for the specified object.

MarginBottom returns or sets the distance (in points) between the bottom of the text frame and the bottom of the inscribed rectangle of the shape that contains the text.

Set myDocument = Worksheets(1) 
With myDocument.Shapes.AddShape(msoShapeRectangle, _ 
 0, 0, 250, 140).TextFrame 
 .Characters.Text = "Here is some test text" 
 .MarginBottom = 0 
 .MarginLeft = 100 
 .MarginRight = 0 
 .MarginTop = 20 
End With

MarginLeft returns or sets the distance (in points) between the left edge of the text frame and the left edge of the inscribed rectangle of the shape that contains the text.

Set myDocument = Worksheets(1) 
With myDocument.Shapes.AddShape(msoShapeRectangle, _ 
 0, 0, 250, 140).TextFrame 
 .Characters.Text = "Here is some test text" 
 .MarginBottom = 0 
 .MarginLeft = 100 
 .MarginRight = 0 
 .MarginTop = 20 
End With

MarginRight returns or sets the distance (in points) between the right edge of the text frame and the right edge of the inscribed rectangle of the shape that contains the text.

Set myDocument = Worksheets(1) 
With myDocument.Shapes.AddShape(msoShapeRectangle, _ 
 0, 0, 250, 140).TextFrame 
 .Characters.Text = "Here is some test text" 
 .MarginBottom = 0 
 .MarginLeft = 100 
 .MarginRight = 0 
 .MarginTop = 20 
End With

MarginTop returns or sets the distance (in points) between the top of the text frame and the top of the inscribed rectangle of the shape that contains the text.

Set myDocument = Worksheets(1) 
With myDocument.Shapes.AddShape(msoShapeRectangle, _ 
 0, 0, 250, 140).TextFrame 
 .Characters.Text = "Here is some test text" 
 .MarginBottom = 0 
 .MarginLeft = 100 
 .MarginRight = 0 
 .MarginTop = 20 
End With

Orientation returns or sets a Long value that represents the text frame orientation.

Parent returns the parent object for the specified object. Read-only.

ReadingOrder returns or sets the reading order for the specified object. Can be one of the following XlReadingOrder constants: xlRTL (right-to-left), xlLTR (left-to-right), or xlContext.

VerticalAlignment returns or sets an XlVAlign value that represents the vertical alignment of the specified object.

VerticalOverflow returns or sets the vertical overflow setting for the specified object.