全部显示

TextFrame 对象

         
多个对象
TextFrame
Ruler
TextRange

代表 Shape 对象中的文字框。包含文本框中的文本,还包含控制文本框对齐方式和缩进方式的属性和方法。

使用 TextFrame 对象

使用 TextFrame 属性返回 TextFrame 对象。以下示例向 myDocument 中添加一个矩形,向矩形中添加文本,然后设置文本框的边距。

Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes _
        .AddShape(msoShapeRectangle, 0, 0, 250, 140).TextFrame
    .TextRange.Text = "Here is some test text"
    .MarginBottom = 10
    .MarginLeft = 10
    .MarginRight = 10
    .MarginTop = 10
End With

使用 HasTextFrame 属性决定形状是否含有文本框,使用 HasText 属性决定文本框是否含有文本,如以下示例所示。

Set myDocument = ActivePresentation.Slides(1)
For Each s In myDocument.Shapes
    If s.HasTextFrame Then
        With s.TextFrame
            If .HasText Then MsgBox .TextRange.Text
        End With
    End If
Next