Shapes.AddTextbox method (Project)

Adds a text box to the report, and returns a Shape object that represents the new text box.

Syntax

expression. AddTextbox (Orientation, Left, Top, Width, Height)

expression A variable that represents a Shapes object.

Parameters

Name Required/Optional Data type Description
Orientation Required MsoTextOrientation The orientation of the text box. Some constants may not be available, depending on the language that is installed.
Left Required Single The position, in points, of the left edge of the text box.
Top Required Single The position, in points, of the top edge of the text box.
Width Required Single The width, in points, of the text box.
Height Required Single The height, in points, of the text box.
Orientation Required MSOTEXTORIENTATION
Left Required FLOAT
Top Required FLOAT
Width Required FLOAT
Height Required FLOAT
Name Required/Optional Data type Description

Return value

Shape

Example

The following example adds a text box with a light yellow background and a visible border. The text string is formatted and manipulated by using members of the TextFrame2 object.

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

See also

Shapes Object Shape Object TextFrame2 Property MsoTextOrientation Enumeration (Office)

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.