Share via


Publisher (的 TextFrame 物件)

代表 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 支援與意見反應