Solved

MouseDown on Excel Chart

Posted on 2001-07-28
7
833 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
Comment Utility
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
Comment Utility
Sorry, it allowed me to increase upto 300 only (I tried 500 first)
0
 
LVL 13

Expert Comment

by:cri
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Author Comment

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

- stochastic
0
 
LVL 13

Expert Comment

by:cri
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How many times recently have you prepared a presentation or emailed a document to a client and you have found that they have older versions of MS Office and they can not open the file you have prepared.  Although most visitors to this site are exper…
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 view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

10 Experts available now in Live!

Get 1:1 Help Now