Shapes.AddTextbox メソッド (Project)

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

構文

expressionAddTextbox(orientation,left,top,width,height)

表現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

関連項目

図形オブジェクト図形オブジェクト TextFrame2 プロパティMsoTextOrientation 列挙型 (Office)

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

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