次の方法で共有


Shapes.AddTextbox メソッド (Project)

レポートにテキスト ボックスを追加し、新しいテキスト ボックスを表す Shape オブジェクトを返します。

構文

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

表現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 のサポートおよびフィードバックを参照してください。