在報告中新增一個文字框,並回傳一個代表新文字框的 Shape 物件。
語法
expression。
AddTextbox
(方向、左側、頂部、寬度、高度)
expression 代表 Shapes 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Orientation | 必要 | MsoTextOrientation | 文字方塊的方向。 根據所安裝的語言,有些常數可能無法使用。 |
| Left | 必要 | Single | 文字框左邊的位置(以 點數計)。 |
| Top | 必要 | Single | 文字框頂端邊緣的位置(以 點數計)。 |
| Width | 必要 | Single | 文字框的寬度(以 點數計)。 |
| Height | 必要 | Single | 文字框的高度(以 點數計)。 |
| Orientation | 必要 | MSOTEXT 導向 | |
| Left | 必要 | 浮 | |
| Top | 必要 | 浮 | |
| Width | 必要 | 浮 | |
| Height | 必要 | 浮 | |
| 名稱 | 必要/選用 | 資料類型 | 描述 |
傳回值
圖形
範例
以下範例新增一個淺黃色背景及可見邊框的文字框。 文字字串透過 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 屬性MsoText 方向列舉 (Office)
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。