共用方式為


Shapes.AddLabel 方法 (專案)

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

語法

expressionAddLabel (方向、左側、頂部、寬度、高度)

expression 代表 Shapes 物件的變數。

參數

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

傳回值

圖形

範例

以下範例會在新報告中新增一個帶有「Hello report!」字樣的綠色標籤。

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 支援與意見反應