次の方法で共有


Shapes.AddLabel メソッド (Project)

レポートにラベルを作成し、新しいラベルを表す Shape オブジェクトを返します。

構文

expressionAddLabel (方向、左、上、幅、高さ)

表現Shapes オブジェクトを表す変数です。

パラメーター

名前 必須 / オプション データ型 説明
Orientation 必須 MsoTextOrientation ラベル内のテキストの向きを指定します。
Left 必須 Single レポートの左側を基準としたラベルの左端の位置 (ポイント単位)。
Top 必須 Single レポートの上端を基準としたラベルの上端の位置 (ポイント単位)。
Width 必須 単精度浮動小数点型 (Single) ラベルの幅をポイント単位で指定します。
Height 必須 単精度浮動小数点型 (Single) ラベルの高さをポイント単位で指定します。
Orientation 必須 MSOTEXTORIENTATION
Left 必須 FLOAT
Top 必須 FLOAT
Width 必須 FLOAT
Height 必須 FLOAT

戻り値

Shape

次の使用例は、新しいレポートに "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

関連項目

Shapes オブジェクトシェイプ オブジェクト

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。