ChartTitle, AxisTitle, and DisplayUnitLabel Members

Use the ChartTitle, AxisTitle, and DisplayUnitLabel objects to add and format captions for charts, axes, and unit labels. These objects have the following members. Key members (shown in bold) are covered in the following reference section:

Application

AutoScaleFont

Border

Caption

Characters

Creator

Delete

Fill

Font

HorizontalAlignment

Interior

Left

Name

Orientation

Parent

ReadingOrder

Select

Shadow

Text

Top

VerticalAlignment

 

The ChartTitle appears at the top of a chart by default, the AxisTitle appears centered next to each axis, and the DisplayUnitLabel appears next to the value axis indicating the units of the value axis (thousands, millions, etc.). Be sure to check the HasTitle or HasDisplayUnitLabel properties before working with these objects.

The following code adds a chart title, axis title, and display unit label to a chart:

Sub AddTitles( )
    Dim chrt As Chart, ax As Axis
    Set chrt = ActiveChart
    ' Add a title.
    chrt.HasTitle = True
    ' Set the chart title caption.
    chrt.ChartTitle.Caption = "FL Home Sales"
    ' Add titles to each axis
    For Each ax In chrt.Axes
        ' Add a title.
        ax.HasTitle = True
        ' Set the axis title
        ax.AxisTitle.Caption = "Axis title"
        ' Add a display unit label caption.
        If ax.Type = xlValue Then
            ax.DisplayUnit = xlThousands
            ax.HasDisplayUnitLabel = True
            ax.DisplayUnitLabel.Caption = "In Thousands"
        End If
    Next
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.