Microsoft Office Tutorials and References
In Depth Information
Understanding Chart Events
An example of using Chart events
To program an event handler for an event taking place on a chart sheet, your VBA code must
reside in the code module for the Chart object. To activate this code module, double-click the
Chart item in the Project window. Then, in the code module, select Chart from the Object
dropdown list on the left and select the event from the Procedure drop-down list on the right (see
Figure 18-12: Selecting an event in the code module for a Chart object.
Because an embedded chart doesn’t have its own code module, the procedure that I
describe in this section works only for chart sheets. You can also handle events for
embedded charts, but you must do some initial setup work that involves creating a
class module. This procedure is described later in “Enabling events for an embedded
The example that follows simply displays a message when the user activates a chart sheet,
deactivates a chart sheet, or selects any element on the chart. I created a workbook with a chart
sheet; then I wrote three event handler procedures named as follows:
h Chart_Activate : Executed when the chart sheet is activated.
h Chart_Deactivate : Executed when the chart sheet is deactivated.
h Chart_Select : Executed when an element on the chart sheet is selected.