» Chart object events using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Events in VBA
VERSION - All Microsoft Excel Versions
Select the desired project in the Project-window.
Insert a new class module by selecting the menu Insert | Class Module.
Activate the new class module and rename it, e.g. ChartEventClass
Copy and paste this example macro to the new class module:
Public WithEvents ChartObject As Chart
Private Sub ChartObject_Select(ByVal ElementID As Long, _
ByVal Arg1 As Long, ByVal Arg2 As Long)
ActiveChart.Deselect
End Sub
' add more macros for the other available chart events if necessary...
After you have finished editing the event macros for the Chart object, you have to add some code to the module ThisWorkbook to activate the new event macros:
Dim ChartObjectClass As New ChartEventClass
Private Sub Workbook_Open()
Set ChartObjectClass.ChartObject = Worksheets(1).ChartObjects(1).Chart
End Sub
After you run the Workbook_Open procedure, the events attached to the first Chart object in the first worksheet are activated.
Book Store:
Recommended Books:
- Special Edition Using Microsoft Excel 2002
- Fish! A Remarkable Way to Boost Morale and Improve Results
- Microsoft Excel 2002 Visual Basic for Applications Step by Step
- H&R Block's Just Plain Smart(tm) Tax Planning Advisor: A year-round approach to lowering your taxes this year, next year and beyond
- What the IRS Doesn't Want You to Know: A Cpa Reveals the Tricks of the Trade
- Lower Your Taxes - Big Time! : Wealth-Building, Tax Reduction Secrets from an IRS Insider
No comments have been submitted.

