TextFrame 对象 (Publisher)

代表 Shape 对象中的文本框。 包含文本框架中的文本以及控制文本框架边距和文本方向的属性。

备注

使用 Shape.TextFrame 属性可返回形状的 TextFrame 对象。

TextRange 属性返回一个 TextRange 对象,该对象代表指定文本框架中的文本范围。

注意

某些形状不支持附加文本 (线条、任意多边形、图片和 OLE 对象,例如) 。 如果试图返回或设置用于控制这些对象的文本框架中文本的属性,那么将发生错误。

文本框架可以链接在一起以使文本从一个形状的文字框架排入另一个形状的文字框架。 使用 NextLinkedTextFramePreviousLinkedTextFrame 要将链接文本框架属性。

示例

下面的示例将当前出版物中第一个形状的文字框架中添加文本,然后设置新文字的格式。

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

使用 Shape.HasTextFrame 属性可确定形状是否具有文本框架,并使用 HasText 属性确定文本框是否包含文本,如以下示例所示。

Sub GetTextFromTextFrame() 
 Dim shpText As Shape 
 
 For Each shpText In ActiveDocument.Pages(1).Shapes 
 If shpText.HasTextFrame = msoTrue Then 
 With shpText.TextFrame 
 If .HasText Then MsgBox .TextRange.Text 
 End With 
 End If 
 Next 
End Sub

下面的示例创建一个文本框 (带有文本框架的矩形) 并向其中添加一些文本。 然后创建另一个文本框,并以使文本从第一个文本框架排入第二个两个文本框架链接在一起。

Sub LinkTextBoxes() 
 Dim shpTextBox1 As Shape 
 Dim shpTextBox2 As Shape 
 
 Set shpTextBox1 = ActiveDocument.Pages(1).Shapes.AddTextbox _ 
 (msoTextOrientationHorizontal, 72, 72, 72, 36) 
 shpTextBox1.TextFrame.TextRange.Text = _ 
 "This is some text. This is some more text." 
 
 Set shpTextBox2 = ActiveDocument.Pages(1).Shapes.AddTextbox _ 
 (msoTextOrientationHorizontal, 72, 144, 72, 36) 
 shpTextBox1.TextFrame.NextLinkedTextFrame = shpTextBox2 _ 
 .TextFrame 
End Sub

方法

属性

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。