Project) (Shapes.AddLabel 方法

在報表中建立標籤,並傳回代表新標籤的 Shape 物件。

語法

expression。 AddLabel (方向,左,頂,寬度,高度)

expression 代表 Shapes 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Orientation 必要 MsoTextOrientation 標籤內的文字方向。
Left 必要 Single 相對於報表左側,標籤左邊緣的點) (位置。
Top 必要 Single 相對於報表頂端,標籤上邊緣) 點 (位置。
Width 必要 Single 標籤的寬度 (以點為單位)
Height 必要 Single 標籤的高度 (以點為單位)
Orientation 必要 MSOTEXTORIENTATION
Left 必要 FLOAT
Top 必要 FLOAT
Width 必要 FLOAT
Height 必要 FLOAT

傳回值

圖形

範例

下列範例會將含有 [您好報表] 文字的綠色標籤新增至新報表。

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

另請參閱

圖形物件圖形物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。