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

Chart.SetElement Method (Project)

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

Adds the specified element to a chart or to a selected object on a chart.


expression. SetElement(RHS)

expression A variable that represents a Chart object.


NameRequired/OptionalData typeDescription
RHSRequiredMsoChartElementTypeOne of the enumeration constants for the chart element type to add.

Return value



The RHS value for the SetElement method corresponds to items in the Add Chart Element submenus. Different items are enabled, depending on the type of chart. If you try to add an element that does not exist for a particular chart, you get an unspecified error. For example, on a 3-D chart, the Error Bars item in the Add Chart Element drop-down list is unavailable. A call to Chart.SetElement msoElementErrorBarStandardDeviation results in an error.


The following example adds minor gridlines to the value axis, and adds data label callouts to the second data series.

Sub TestSetElements()
    Dim chartShape As Shape
    Dim reportName As String

    reportName = "Simple 3-D chart"
    Set chartShape = ActiveProject.Reports(reportName).Shapes(1)

    With chartShape.Chart
        .SetElement msoElementChartTitleAboveChart

        ' Select the major gridlines on the value axis, and then add minor gridlines.
        .SetElement msoElementPrimaryCategoryGridLinesMinor

        ' Select the second data series and add data label callouts.
        If .SeriesCollection.Count > 1 Then
            .SetElement msoElementDataLabelCallout
        End If
    End With
End Sub

See also

Other resources

Chart Object

© 2018 Microsoft