VBA Excel - Mouse cursor coordinates

csehz
csehz used Ask the Experts™
on
Dear Experts,

Could you please have a look at the attached excel file, it contains an AutoShape with weight 5pt.

My question would be that is it possible through VBA to check what are the mouse cursor coordinates, and for example entering 1 to cell A1 if it is over of the authoshape, and leaving on 0 if the mouse cursor is not over on it?

thanks,
Cursor-position.xls
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I don't know if you can do that with autoshapes, but ActiveX controls have a MouseMove event which may do what you want. See very rudimentary attachment - you have to click somewhere on the worksheet to make A1 return to zero. I haven't really dabbled in this stuff - I'm sure others will have much better solutions.
Cursor-position.xls
csehzIT consultant

Author

Commented:
Generally thanks your answer, basically your example gives the solution or ideas about it.

Anyway I also started to go to such direction, because from Control Toolbox if we select Image, the following code brings the coordinates

Private Sub Image1_MouseMove(ByVal Button As Integer, _
  ByVal Shift As Integer, ByVal X As Single, _
  ByVal Y As Single)
    Application.StatusBar = Round(X, 0) & "," & Round(Y, 0)
End Sub

And maybe indirectly but somehow like this could be done.

Do you think that if so the cursor coordinates can be identified over an image, could it say that what is the color of that pixel?

thanks in advance,
I'm afraid I can honestly say that I am out of my depth on that one! Wait for someone more knowledgeable to happen by.
Though when you say pixel, do you mean cell?
csehzIT consultant

Author

Commented:
I would mean pixel color not cell.

Because my idea would be that this original curve with blue color, if this would be on an Image object so having finally just two colours in total on the picture, in that case maybe the difference of the color would say whether the mouse pointer is over it or not.
csehzIT consultant

Author

Commented:
Generally got the orientation that in which direction the solution can be to determine mouse coordinates

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial