Solved

MouseDown on Excel Chart

Posted on 2001-07-28
7
848 Views
Last Modified: 2012-05-04
I have a XY Scatter chart as an object on an Excel sheet. I want to allow the user to click anywhere on the chart, upon which I want to call a procedure (sub). The procedure should be able to receive the co-ordinates relative in the chart's axis scales. How do I do this?

I have already got thus far:
a. The Chart_MouseDown seems to work okay, only on a chartsheet, not on a chart object on a worksheet. (For a worksheet object, I could not find a chart_mousedown event handler)

b. I can get the mouse position, but in the form of the location in the window. How do I transform this to co-ordinates in the XY frame of the chart?

thanks,
stochastic
0
Comment
Question by:stochastic
  • 4
  • 3
7 Comments
 
LVL 8

Author Comment

by:stochastic
ID: 6358207
Ten days, not one response! Hey, that's uncharacteristic. What are all the E's doing?

Here, I quintuple the ante. Can do an encore if necessary. C'mon folks, I need serious help here.

- stochastic
0
 
LVL 8

Author Comment

by:stochastic
ID: 6358208
Sorry, it allowed me to increase upto 300 only (I tried 500 first)
0
 
LVL 13

Expert Comment

by:cri
ID: 6375700
Regarding a)

- Insert|Class Module
- Rename it EventClassModule using the Property window
- Paste this code:
Public WithEvents myChartClass As Chart

Then in any regular VBA module, paste this initializing code:

Dim myClassModule As New EventClassModule

Sub InitializeChart()
    Set myClassModule.myChartClass = Worksheets(1).ChartObjects(1).Chart '<Adapt
End Sub

Regarding b), well, this is anoter story. Place this preliminary 'code' in the new class module:

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
  With myChartClass
    MsgBox "Clicked at x=" & X & " 'cc', y=" & Y & " 'cc'"
    With .ChartArea
      MsgBox "ChartArea: W= " & .Width & " pts, H=" & .Height & " pts, etc., etc."
      MsgBox "BUT: How to make a coordinate transformation without scale or reference point ?"
    End With
  End With
End Sub

Remark:
- Looks like you have to run the initializing Sub again if you bomb it, Reset/Compile does not seem to be enough.
- As mentioned above, I have no clue (yet ?) how to make the necessary coordinate transformation, if you have some clue how to return some additional information like a width in client coordinates I can finish this. Otherwise I do only see the clumsy method of having to select more or less precisely the TopLeft and BottomRight corners of the plot area or similar before doing whatever you want to have done.


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Author Comment

by:stochastic
ID: 6376773
thanks cri,
I will look at this and get back with more.

- stochastic
0
 
LVL 13

Expert Comment

by:cri
ID: 6376790
Should my directions be too shorthand, see Excel VBA Help under 'Event Embedded Chart' (w/o quotes).
0
 
LVL 13

Accepted Solution

by:
cri earned 300 total points
ID: 6376807
What are you actually want to accomplish ? Perhaps a neat work-around can be devised, as this one:
http://www.j-walk.com/ss/excel/tips/tip66.htm
0
 
LVL 8

Author Comment

by:stochastic
ID: 6675695
cri,

just closing this long-standing question. Your comments were helpful, though I need to get deeper into this to achieve exactly what I need.

thanks anyways.
- stochastic
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now