Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MouseDown on Excel Chart

Posted on 2001-07-28
7
Medium Priority
?
970 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
New style of hardware planning for Microsoft Exchange server.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

618 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