Table of contents
TOC
Collapse the table of content
Expand the table of content

Shapes.AddTextbox Method (Project)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

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

NameRequired/OptionalData TypeDescription
OrientationRequiredMsoTextOrientationThe orientation of the text box. Some constants may not be available, depending on the language that is installed.
LeftRequiredSingleThe position, in points, of the left edge of the text box.
TopRequiredSingleThe position, in points, of the top edge of the text box.
WidthRequiredSingleThe width, in points, of the text box.
HeightRequiredSingleThe height, in points, of the text box.
OrientationRequiredMSOTEXTORIENTATION
LeftRequiredFLOAT
TopRequiredFLOAT
WidthRequiredFLOAT
HeightRequiredFLOAT
NameRequired/OptionalData typeDescription

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 is 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

Other resources

Shapes ObjectShape ObjectTextFrame2 PropertyMsoTextOrientation Enumeration (Office)

© 2018 Microsoft