Chart
Event | Description | 365 | 21 | 16 | 13 | 10 | 07 |
Activate Cast (ChartEvents_Event) | Occurs when an embedded chart or chart object on a chart sheet is selected. This should be used instead of the OnSheetActivate property. | Y | Y | Y | Y | Y | Y |
BeforeDoubleClick | Occurs before an embedded chart or chart object on a chart sheet is double clicked. This should be used instead of the OnDoubleClick property. | Y | Y | Y | Y | Y | Y |
BeforeRightClick | Occurs before an embedded chart or chart object on a chart sheet is right clicked. | Y | Y | Y | Y | Y | Y |
Calculate | Occurs before any new data is plotted or data changes. This is raised on a chart sheet that was updated because data it referenced changed. This event does not occur until the chart is forced to redraw. So if the chart is not currently visible because it is not selected or displayed in its own window the event will not be raised until the chart is visible | Y | Y | Y | Y | Y | Y |
Deactivate | Occurs when a new embedded chart or chart sheet is activate and another embedded chart, chart sheet or worksheet is selected. This should be used instead of the OnSheetDeactivate property. | Y | Y | Y | Y | Y | Y |
MouseDown | Occurs when a mouse button is pressed while the pointer is over an embedded chart or chart sheet. | Y | Y | Y | Y | Y | Y |
MouseMove | Occurs when the mouse pointer is moved over the chart | Y | Y | Y | Y | Y | Y |
MouseUp | Occurs when a mouse button is released while the pointer is over an embedded chart or chart sheet | Y | Y | Y | Y | Y | Y |
Resize | Occurs when a chart is resized | Y | Y | Y | Y | Y | Y |
Select Cast (ChartEvents_Event) | Occurs when a chart element is selected Raised when the selected element within a chart sheet changes. The combination of the three parameters allows you to determine exactly what element is selected. | Y | Y | Y | Y | Y | Y |
SeriesChange | Occurs when a value of a chart data point changes. | Y | Y | Y | Y | Y | Y |
Writing Chart Events
This object does not have events enabled by default.
You must write your own event handler routines when you want to capture chart events for embedded charts.
If you want to capture the chart events for a specific chart sheet the event handlers are available in an identical way to the worksheet level events.
The advantage of this method is that you can run the same event handler for different chart objects.
Public WithEvents ExcelChartEvents As Chart
Dim Chart1 As New EventClass
Dim Chart2 As New EventClass
Set Chart1.ExcelChartEvents = Worksheets(1).ChartObjects(1).Chart
Set Chart2.ExcelChartEvents = Worksheets(1).ChartObjects(2).Chart
Embedded Chart Events
Add a class module to trap the events
Add a standard module to hook the event handler to your charts
The exact code will depend on your situation but there are a wide range of different scenarios from all charts in all sheets in all workbooks to just a single chart in a specific workbook.
Chart Select Event
Or you can use a Chart object declared in a class module to write an event handler for both embedded charts and chart sheets.
This event has three arguments passed to it
ElementID - Identifies the chart element (xlChartItem) enumeration
Arg1 - provides additional information
xlErrorBars | SeriesIndex |
xlXErrorBars | SeriesIndex |
xlYErrorBars | SeriesIndex |
xlLegendEntry | SeriesIndex |
xlLegendKey | SeriesIndex |
xlUpBars | GroupIndex |
xlDownBars | GroupIndex |
xlSeriesLines | GroupIndex |
xlHiLoLines | GroupIndex |
xlDropLines | GroupIndex |
xlRadarAxisLabels | GroupIndex |
xlShape | ShapeIndex |
xlPivotChartDropZone | DropZoneType |
Arg2 - provides additional information
xlSeries | SeriesIndex | PointIndex |
xlDataLabel | SeriesIndex | PointIndex |
xlTrendLine | SeriesIndex | TrendLineIndex |
xlAxis | AxisIndex | AxisType |
xlMajorGridlines | AxisIndex | AxisType |
xlMinorGridlines | AxisIndex | AxisType |
xlAxisTitle | AxisIndex | AxisType |
xlDisplayUnitLabel | AxisIndex | AxisType |
xlPivotChartFieldButton | DropZoneType | PivotFieldIndex |
Chart MouseUp Event
This event has four arguments passed to it
Button - Identifies which button was released (xlMouseButton)
Shift - Identifies if any other keys were pressed (Ctrl, Shift, Alt)
x - Identifies the x-coordinate
y - Identifies the y-coordinate
Change Events
Change events are typically raised when a user exist cell edit mode by leaving the cell or pressing Enter
Change events can also be raised when a cell is linked to external data and it changes as a result of refreshing the external data.
Change events are not raised as a result of recalculation
Application.SheetChange
Workbook.SheetChange
Worksheet.Change
Event Procedures
Private Sub Chart_Activate()
End Sub
Private Sub Chart_BeforeDoubleClick( _
ByVal ElementID As Long, _
ByVal Arg1 As Long, _
ByVal Arg2 As Long, _
ByRef Cancel As Boolean)
End Sub
Private Sub Chart_BeforeRightClick( _
ByRef Cancel As Boolean)
End Sub
Private Sub Chart_Calculate()
End Sub
Private Sub Chart_Deactivate()
End Sub
Private Sub Chart_MouseDown( _
ByVal Button As Long, _
ByVal Shift As Long, _
ByVal x As Long, _
ByVal y As Long)
End Sub
Private Sub Chart_MouseMove( _
ByVal Button As Long, _
ByVal Shift As Long, _
ByVal x As Long, _
ByVal y As Long)
End Sub
Private Sub Chart_MouseUp( _
ByVal Button As Long, _
ByVal Shift As Long, _
ByVal x As Long, _
ByVal y As Long)
End Sub
Private Sub Chart_Resize()
End Sub
Private Sub Chart_Select( _
ByVal ElementID As Long, _
ByVal Arg1 As Long, _
ByVal Arg2 As Long)
End Sub
Private Sub Chart_SeriesChange( _
ByVal SeriesIndex As Long, _
ByVal PointIndex As Long)
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext