Chart_select event problem

P

PO

Hi,

I'm using a class to trap an embedded charts events.

Private Sub EmbChart_Select(ByVal ElementID As Long, ByVal Arg1 As Long,
ByVal Arg2 As Long)

If Arg2 < 0 Or ElementID <> 3 Then Exit Sub

Dim dblPotential As Double
Dim dblEnergy As Double
Dim sName As String

sName = wksEmbchart.Range("inpName").Cells(Arg2, 1).Value

dblPotential = wksEmbchart.Range("inpName").Cells(Arg2, 2).Value
dblEnergy = wksEmbchart.Range("inpName").Cells(Arg2, 3).Value

...some more code here
End Sub

The code works just fine, there is however one slight problem. The user has
to click the datapoint 2 times. The first click selects the series (Arg2
= -1) and not the point. Is there any way around this, i.e. can the user
click the datapoint without the series getting selected?

Regards
Pete
 
P

Peter T

Not guranteed to work but should work most of the time (run startChartEvents
to instantiate the withevents class)

' code in a normal module

Dim cls As Class1

Sub startChartEvents()
Set cls = New Class1
Set cls.cht = ActiveSheet.ChartObjects(1).Chart
End Sub

Sub stopChartEvents()
Set cls = Nothing
End Sub


' code in class odule named Class1

Public WithEvents cht As Chart
Private mX As Long, mY As Long

Private Sub cht_MouseMove(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
mX = x
mY = y
End Sub

Private Sub cht_Select(ByVal ElementID As Long, _
ByVal Arg1 As Long, ByVal Arg2 As Long)
Dim eID As Long, a1 As Long, a2 As Long
If ElementID = xlSeries And Arg2 = -1 Then
Call cht.GetChartElement(mX, mY, eID, a1, a2)
If eID = xlSeries And a1 = Arg1 And a2 > 0 Then
cht.SeriesCollection(a1).Points(a2).Select
End If
End If
End Sub

Presumably you'll implement some other way to select the entire series!

Regards,
Peter T
 

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