DataTable Members

Use the DataTable object to control the appearance of a data table on a chart sheet. Use the Chart object’s DataTable property to get a reference to this object. The DataTable object has the following members:

Application

AutoScaleFont

Border

Creator

Delete

Font

HasBorderHorizontal

HasBorderOutline

HasBorderVertical

Parent

Select

ShowLegendKey

Most of the DataTable members are True/False properties that enable or disable specific data table items. These properties correspond to the settings on the Format Data Table dialog box (Figure 16-9).

Before you use the DataTable object, make sure to set the chart’s HasDataTable property to True—that creates the table if it did not already exist. The following code adds a data table to the active chart and sets some of the table’s properties:

Sub AddDataTable(  )
    Dim chrt As Chart, dt As DataTable
    ' Get the chart.
    Set chrt = ActiveChart
    ' Add a data table if it doesn't have one.
    chrt.HasDataTable = True
    ' Get the data table.
    Set dt = chrt.DataTable
    ' Set the data table properties.
    ' These properties are all True by default:
    dt.ShowLegendKey = False
    dt.HasBorderHorizontal = False
    dt.HasBorderOutline = True
    dt.HasBorderVertical = True
End Sub
Data table properties correspond to these settings

Figure 16-9. Data table properties correspond to these settings

Data tables may appear on chart sheets or on embedded charts, but some chart types, such as xy scatter charts, do ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.