![]() |
Chart events
Hello I have searched the web to find out how to use events in a chart but without success. I found some code, but it does not work for me. Can someone help me please? Thanks in advance *** Sent via Developersdex http://www.developersdex.com *** |
Chart events
Hello, "how to use events in charts" and "found some code" is a bit vague. Maybe you can describe what you would like to achieve? cheers, teylyn kalle;714869 Wrote: Hello I have searched the web to find out how to use events in a chart but without success. I found some code, but it does not work for me. Can someone help me please? Thanks in advance *** Sent via Developersdex 'Developersdex.com - The Web Developers Index and Directory' (http://www.developersdex.com) *** -- teylyn Teylyn -- 'teylyn.posterous.com' (http://teylyn.posterous.com) ------------------------------------------------------------------------ teylyn's Profile: http://www.thecodecage.com/forumz/member.php?u=983 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=200094 http://www.thecodecage.com/forumz |
Chart events
Thanks for your answer I use code that I found here. http://www.exceltip.com/st/Chart_obj...n_Microsoft_Ex cel/439.html I put this in a 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 and then i try to run this from a standard module Dim ChartObjectClass As New ChartEventClass Private Sub Workbook_Open() Set ChartObjectClass.ChartObject = Worksheets(1).ChartObjects(1).Chart End Sub When I do, I get a compile error (User-defined type not defined) What I eventually want to do is double click on a bar in the graph and find the X category. In this case, for example, 2010-03. Then it will be used to run a sql query to display detailed data for the month. So with this code I just try to understan how chart envents works and if it's possible for me to use. *** Sent via Developersdex http://www.developersdex.com *** |
Chart events
' code in a normal module
Private clsChart As ChartEventClass Sub StartEvents() Dim ch As Chart Set ch = Worksheets("Sheet1").ChartObjects(1).Chart Set clsChart = New ChartEventClass Set clsChart.cht = ch End Sub ' code in a class named ChartEventClass Public WithEvents cht As Chart Private Sub cht_Select(ByVal ElementID As Long, ByVal Arg1 As Long, _ ByVal Arg2 As Long) Dim sMsg As String Dim sr As Series Select Case ElementID Case xlSeries Set sr = cht.SeriesCollection(Arg1) sMsg = sr.Name If Arg2 0 Then sMsg = sMsg & vbCr & "Point " & Arg2 End If Case xlPlotArea sMsg = "PlotArea" ' etc Case Else sMsg = "ElementID" & ElementID & vbCr & _ "Arg1 " & Arg1 & vbCr & _ "Arg2 " & Arg2 End Select MsgBox sMsg End Sub Put a chart on Sheet1, run StartEvents, select a Series and/or a Point You may way to add another routing to do Set clsChart = Nothing possibly in the Worksheet & Workbook deactivate events Regards, Peter T "kalle" wrote in message ... Hello I have searched the web to find out how to use events in a chart but without success. I found some code, but it does not work for me. Can someone help me please? Thanks in advance *** Sent via Developersdex http://www.developersdex.com *** |
Chart events
I don't know if it's the problem, but ChartObject is a dumb choice for a
variable name, (a) since it's a keyword, and (b) since it refers to a different object in Excel's object model. Go to Google, and search on Excel Chart Events. The first article is a very comprehensive guide. - Jon ------- Jon Peltier Peltier Technical Services, Inc. http://peltiertech.com/ On 5/3/2010 5:20 AM, kalle wrote: Thanks for your answer I use code that I found here. http://www.exceltip.com/st/Chart_obj...n_Microsoft_Ex cel/439.html I put this in a 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 and then i try to run this from a standard module Dim ChartObjectClass As New ChartEventClass Private Sub Workbook_Open() Set ChartObjectClass.ChartObject = Worksheets(1).ChartObjects(1).Chart End Sub When I do, I get a compile error (User-defined type not defined) What I eventually want to do is double click on a bar in the graph and find the X category. In this case, for example, 2010-03. Then it will be used to run a sql query to display detailed data for the month. So with this code I just try to understan how chart envents works and if it's possible for me to use. *** Sent via Developersdex http://www.developersdex.com *** |
All times are GMT +1. The time now is 01:57 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com