Mouse Pointer Position

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
Hi, I think I need to use an API function for this, but I've not used them before.

I want to be able to ascertain the x and y co-ordinates of the current position of the mouse pointer. ie, not the selected cell, but the mouse arrow itself. Any ideas?

Thanks
 
I'd like to be able to add a shape when the mouse is pointing on a worksheet. Obviously I could add the shape and then move it to where I want it, but the project I'm working on requires this to be done many times, so it would be much quicker and less tedious if it were possible.
 
Upvote 0
Here's another from Hans Herber:

Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Sub WhereAmI()
Dim pTargetPoint As POINTAPI
Dim lRetVal As Long
lRetVal = GetCursorPos(pTargetPoint)
MsgBox "My Position:" & vbLf & pTargetPoint.x & "," & pTargetPoint.y
End Sub


Hey Dan - - Thanks for re-posting that link...makes the mouse look like it's on steroids with all the value changes in the linked cell, kind of cool.
 
Upvote 0
Thanks guys, That's a great start. Now I'm trying to figure out how I can "calibrate" the screen x,y pixel co-ordinates with the points position on my spreadsheet. Any tips would be great.

Thanks
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top