Chart events

K

kalle

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 ***
 
T

teylyn

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 said:
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) ***
 
K

kalle

Thanks for your answer

I use code that I found here.

http://www.exceltip.com/st/Chart_object_events_using_VBA_in_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 ***
 
P

Peter T

' 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
 
J

Jon Peltier

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top