Open userform on MouseMove at a prticular point

  • Thread starter Thread starter mangesh_yadav
  • Start date Start date
M

mangesh_yadav

I am showing some data in a UserForm on a chart using the MouseMov
event. When I move the mouse over a series, the form opens up showin
some data.

I want to open the form exactly at the point where the mouse is, fo
which I use the following code:


Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long
ByVal x As Long, ByVal y As Long)

ActiveChart.GetChartElement x, y, IDNum, a, b
' here x, y are the positions of the chart

UserForm.StartUpPosition = 0
UserForm.left = x
UserForm.top = y

UserForm.Show

--------------

But the problem is that the form does not open near the mouse cursor
Any ideas...

- Manges
 
Hi Mangesh -

Welcome to the world of relative coordinate systems. X and Y in the chart event are
in chart object client coordinates, which are in pixels from the top left of the
chartobject object. On my system, a point is 0.75 pixels; this depends on the
Windows font size setting (large fonts/small fonts). The chartobject's position from
the top left of cell A1 is given by the .Top and .Left properties of the
ChartObject. A UserForm is positioned relative to the top left of the screen (the
main screen if you're using multiple monitors), in points.

Chip Pearson has a neat utility on his web site that helps you locate forms relative
to cells in the Excel window. It accounts for scrolled windows, toolbars, etc.
You'll have to work with it a little to account for the position of the click within
the chart.

http://cpearson.com/excel/FormPosition.htm

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top