Shapes.AddLabel 方法 (Project)

在报表中创建标签,并返回一个代表新标签的 Shape 对象。

语法

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

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

参数

名称 必需/可选 数据类型 说明
Orientation 必需 MsoTextOrientation 标签中文本的方向。
Left 必需 Single 标签左边缘相对于报表左侧的位置 () 磅。
Top 必需 Single 标签上边缘相对于报表顶部的位置 () 磅。
Width 必需 Single 标签的宽度(以磅为单位)。
Height 必需 Single 标签的高度(以磅为单位)。
Orientation 必需 MSOTEXTORIENTATION
Left 必需 FLOAT
Top 必需 FLOAT
Width 必需 FLOAT
Height 必需 FLOAT

返回值

Shape

示例

以下示例向新报表添加带有文本“Hello报表!”的绿色标签。

Sub AddHelloLabel()
    Dim shapeReport As Report
    Dim reportName As String
    Dim labelShape As shape
    
    ' Add a report.
    reportName = "Label report"
    Set shapeReport = ActiveProject.Reports.Add(reportName)

    Set labelShape = shapeReport.Shapes.AddLabel(msoTextOrientationHorizontal, 30, 30, 120, 40)

    With labelShape
        With .Fill
            .BackColor.RGB = RGB(red:=&H20, green:=&HFF, blue:=&H20)
            .Visible = msoTrue
        End With
        
        .TextFrame2.AutoSize = msoAutoSizeShapeToFitText
        .TextFrame2.HorizontalAnchor = msoAnchorCenter
        
        With .TextFrame2.TextRange
            .Text = "Hello report!"
            .Font.Bold = msoTrue
            .Font.Name = "Calibri"
            .Font.Size = 18
        End With
    End With
End Sub

另请参阅

Shapes 对象形状对象

支持和反馈

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