ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Chart events

Events for the chart object occurs when the user activates or changes a chart. Events in charts are activated by default, but can be deactivated by a macro. To display the event procedures for a chart you use the Visual Basic editor. Select the desired project in the Project-window and activate the chart object you want by doubleclicking it. Any event procedures in the chart will now be displayed in the Code-window on the right side of the screen. You can create a new event procedure by selecting Chart in the Object dropdown, and then select an event in the Procedure dropdown.
Macros can be attached to the following events in a chart :

Activate
BeforeDoubleClick
BeforeRightClick
Calculate
Deactivate
DragOver
DragPlot
MouseDown
MouseMove
MouseUp
Resize
Select
SeriesChange

This example eventmacro will prevent the user from selecting and editing objects in a chart, the procedure must be written in the charts own module sheet, e.g. Chart1:

Private Sub Chart_Select(ByVal ElementID As Long, _
    ByVal Arg1 As Long, ByVal Arg2 As Long)
    ActiveChart.Deselect
End Sub

 

Document last updated 1999-08-21 12:47:53      Printerfriendly version

User comments:
Ole P. from Norway wrote (2004-10-14 17:26:38 CET):
Re: ALMOST PERFECT
Event macros are triggered by, well events. You don't start these macros yourself and there is no need to pass any arguments, the applicaation (Excel) will do this.
You can however add your own functionality to these events by adding code to the events macros like the simple example above.
Usually you would write a procedure that performs a task in a normal module sheet, then you add the procedure name to the event that you want to trigger (start) your macro.
MELISSA from SPAIN wrote (2004-10-13 22:58:37 CET):
ALMOST PERFECT
IT'S GOOD BUT...WHAT ABOUT A LITLE DOWN EXEMPLE OF HOW TO USE IT. FOR EXEMPLE I DIDN'T UNDERSTUD WHAT MUST PASS AS ARGUMENTS ???

THANKS

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address