將文字方塊新增至報表,並傳回代表新文字方塊的 Shape 物件。
語法
expression。
AddTextbox
(方向,左,頂,寬度,高度)
expression 代表 Shapes 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Orientation | 必要 | MsoTextOrientation | 文字方塊的方向。 根據安裝的語言而定,某些常數可能無法使用。 |
| Left | 必要 | Single | 文字方塊左邊緣的位置, 以點為單位。 |
| Top | 必要 | Single | 文字方塊上邊緣的位置, 以點為單位。 |
| Width | 必要 | Single | 文字方塊的寬度, 單位點。 |
| Height | 必要 | Single | 文字方塊的高度, 單位點。 |
| Orientation | 必要 | MSOTEXTORIENTATION | |
| Left | 必要 | FLOAT | |
| Top | 必要 | FLOAT | |
| Width | 必要 | FLOAT | |
| Height | 必要 | FLOAT | |
| 名稱 | 必要/選用 | 資料類型 | 描述 |
傳回值
圖形
範例
下列範例會新增具有淺黃色背景和可見框線的文字方塊。 使用 TextFrame2 物件的成員來格式化和操作文字字串。
Sub AddTextBoxShape()
Dim theReport As Report
Dim textShape As shape
Dim reportName As String
reportName = "Textbox report"
Set theReport = ActiveProject.Reports.Add(reportName)
Set textShape = theReport.Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 50, 300, 100)
textShape.TextFrame2.TextRange.Characters.Text = "This is a test. It's only a test. " _
& "If it had been real information, there would be some real text here."
textShape.TextFrame2.TextRange.Characters(1, 15).ParagraphFormat.FirstLineIndent = 10
textShape.TextFrame2.TextRange.Characters(16).InsertBefore vbCrLf
' Set the font for the first 15 characters to dark blue bold.
With textShape.TextFrame2.TextRange.Characters(1, 15).Font
.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent5
.Fill.Solid
.Fill.Visible = msoTrue
.Size = 14
.Bold = msoTrue
End With
With textShape.Fill
.ForeColor.RGB = RGB(255, 255, 160)
.Visible = msoTrue
End With
With textShape.Line
.Weight = 1
.Visible = msoTrue
End With
End Sub
另請參閱
圖形物件圖形物件TextFrame2 屬性Office) (MsoTextOrientation 列舉
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。