Shapes.AddTextbox 方法 (Project)

向报表添加文本框,并返回一个代表新文本框的 Shape 对象。

语法

expressionAddTextbox (方向、左侧、顶部、宽度、高度)

expression:一个表示 Shapes 对象的变量。

参数

名称 必需/可选 数据类型 说明
Orientation 必需 MsoTextOrientation 文本框的方向。 某些常量可能不可用,具体取决于安装的语言。
Left 必需 Single 文本框左边缘的位置(以 为单位)。
Top 必需 Single 文本框上边缘的位置(以 为单位)。
Width 必需 Single 文本框的宽度(以 为单位)。
Height 必需 Single 文本框的高度(以 为单位)。
Orientation 必需 MSOTEXTORIENTATION
Left 必需 FLOAT
Top 必需 FLOAT
Width 必需 FLOAT
Height 必需 FLOAT
名称 必需/可选 数据类型 说明

返回值

Shape

示例

以下示例添加一个带有浅黄色背景和可见边框的文本框。 文本字符串是使用 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

另请参阅

Shapes 对象形状对象TextFrame2 属性MsoTextOrientation 枚举 (Office)

支持和反馈

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