Chart.Axes method (Project)

Returns an object that represents either a single axis or a collection of the axes on the chart.

Syntax

expression.Axes (Type, AxisGroup)

expression A variable that represents a Chart object.

Parameters

Name Required/Optional Data type Description
Type Optional Variant Specifies the axis to return. Can be one of the following Office.XlAxisType constants: xlValue, xlCategory, or xlSeriesAxis (xlSeriesAxis is valid only for 3D charts).
AxisGroup Optional Office.XlAxisGroup Specifies the axis group. The default value is xlPrimary; that is, if the AxisGroup argument is omitted, the primary group is used. 3D charts have only one axis group.
Type Optional Variant
AxisGroup Optional XLAXISGROUP

Return value

Object

Examples

The SetAxisTitle macro adds an axis label to the category axis in the chart.

Sub SetAxisTitle()
    Dim chartShape As Shape
    Dim reportName As String
    
    reportName = "Simple scalar chart"
    
    Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
    
    With chartShape.Chart.Axes(xlCategory)
        .HasTitle = True
        .AxisTitle.Text = "Task"
    End With
End Sub

The AddCategoryGridlines macro adds gridlines to the category axis in the chart.

Sub AddCategoryGridlines()
    Dim chartShape As Shape
    Dim reportName As String
    
    reportName = "Simple scalar chart"
    
    Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
    
    chartShape.Chart.Axes(xlCategory).HasMajorGridlines = True
End Sub

The RemoveGridlines macro removes the major gridlines from both the category and value axes.

Sub RemoveGridlines()
    Dim chartShape As Shape
    Dim reportName As String
    Dim axes As Object
    Dim a As Object
    
    reportName = "Simple scalar chart"
    
    Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
    
    chartShape.Chart.Axes(xlCategory).HasMajorGridlines = False
    chartShape.Chart.Axes(xlValue).HasMajorGridlines = False
End Sub

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.