?
Solved

MouseDown on Excel Chart

Posted on 2001-07-28
7
Medium Priority
?
942 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

777 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