Shapes.AddChart method (Project)

Creates a chart at the specified location on the active report. Returns a Shape object that represents the chart.

Syntax

expression. AddChart (Style, Type, Left, Top, Width, Height, NewLayout)

expression A variable that represents a Shapes object.

Parameters

Name Required/Optional Data type Description
Style Optional Integer Specifies the color style of the chart. The values correspond to the Change Colors drop-down list on the Chart Styles group, on the DESIGN tab, under CHART TOOLS on the ribbon (but the values are not in the same order).
Type Optional xlChartType The type of chart to add, such as a column chart or pie chart.
Left Optional Single The position, measured in points, of the left edge of the chart.
Top Optional Single The position, measured in points, of the top edge of the chart.
Width Optional Single The width of the chart, measured in points.
Height Optional Single The height of the chart, measured in points.
NewLayout Optional Boolean NewLayout is not used in Project.
Style Optional INT
Type Optional XLCHARTTYPE
Left Optional FLOAT
Top Optional FLOAT
Width Optional FLOAT
Height Optional FLOAT
NewLayout Optional BOOL
Name Required/Optional Data type Description

Return value

Shape

Example

The following example creates a report that has a default bar chart type with orange-colored bars.

Sub AddDefaultChart()
    Dim chartReport As Report
    Dim reportName As String
    
    ' Add a report.
    reportName = "Test chart report"
    Set chartReport = ActiveProject.Reports.Add(reportName)

    ' Add a chart.
    Dim chartShape As shape
    Set chartShape = ActiveProject.Reports(reportName).Shapes.AddChart(Style:=12)
    
    With chartShape
        .Chart.SetElement msoElementChartTitleAboveChart
        .Chart.ChartTitle.Text = "Test Chart"
    End With
End Sub

See also

Shapes Object Shape Object Chart Object

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.