GetChartElement Method

Applies To

Chart object.

Description

Returns information about the chart element at specified X and Y coordinates. This method is unusual in that you specify values for only the first two arguments. Microsoft Excel fills in the other arguments, and your code should examine those values when the method returns.

Syntax

expression.GetChartElement(X, Y, ElementID, Arg1, Arg2)

expression Required. An expression that returns a Chart object.

X Required Long. The X coordinate of the chart element.

Y Required Long. The Y coordinate of the chart element.

ElementID Required Long. When the method returns, this argument contains the XLChartItem value of the chart element at the specified coordinates. For more information, see the "Remarks" section.

Arg1 Required Long. When the method returns, this argument contains information related to the chart element. For more information, see the "Remarks" section.

Arg2 Required Long. When the method returns, this argument contains information related to the chart element. For more information, see the "Remarks" section.

Remarks

The value of ElementID after the method returns determines whether Arg1 and Arg2 contain any information, as shown in the following table.

ElementID

Arg1

Arg2

xlChartArea

None

None

xlChartTitle

None

None

xlPlotArea

None

None

xlLegend

None

None

xlFloor

None

None

xlWalls

None

None

xlCorners

None

None

xlDataTable

None

None

xlSeries

SeriesIndex

PointIndex

xlDataLabel

SeriesIndex

PointIndex

xlTrendline

SeriesIndex

TrendLineIndex

xlErrorBars

SeriesIndex

None

xlXErrorBars

SeriesIndex

None

xlYErrorBars

SeriesIndex

None

xlLegendEntry

SeriesIndex

None

xlLegendKey

SeriesIndex

None

xlAxis

AxisIndex

AxisType

xlMajorGridlines

AxisIndex

AxisType

xlMinorGridlines

AxisIndex

AxisType

xlAxisTitle

AxisIndex

AxisType

xlUpBars

GroupIndex

None

xlDownBars

GroupIndex

None

xlSeriesLines

GroupIndex

None

xlHiLoLines

GroupIndex

None

xlDropLines

GroupIndex

None

xlRadarAxisLabels

GroupIndex

None


(continued)

xlShape

ShapeIndex

None

xlNothing

None

None


The following table describes the meaning of Arg1 and Arg2 after the method returns.

Argument

Description

SeriesIndex

Specifies the offset within the Series collection for a specific series.

PointIndex

Specifies the offset within the Points collection for a specific point within a series. A value of – 1 indicates that all data points are selected.

TrendlineIndex

Specifies the offset within the Trendlines collection for a specific trendline within a series.

AxisIndex

Specifies whether the axis is primary (0) or secondary (1).

AxisType

Specifies the axis type: Category (0), Value (1), or Series (2).

GroupIndex

Specifies the offset within the ChartGroups collection for a specific chart group.

ShapeIndex

Specifies the offset within the Shapes collection for a specific shape.


Example

This example warns the user if she moves the mouse over the chart legend.

Private Sub Chart_MouseMove(ByVal Button As Long, _
        ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
    Dim IDNum As Long
    Dim a As Long
    Dim b As Long

    ActiveChart.GetChartElement X, Y, IDNum, a, b
    If IDNum = xlLegendEntry Then _
        MsgBox "WARNING: Move away from the legend"
End Sub