Link to home
Start Free TrialLog in
Avatar of verasen
verasen

asked on

Get screen coordinates of cursor in MS Word

I need to get the x,y screen pixel coordinates of the cursor (also known as Caret) in MS Word. Anyone know how?
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

What exactly are you trying to do, just get the screen co ordinates on a userform from VBA or are you trying to select a word that is underneath the mouse cursor or what ?
Apparently s/he just wants to get the Point location of the Caret (the blinky thing when you type)... I don't do VB myself.. but I'm not too sure if you can actually get the screen co-ordinates with an existing API.. What I would personally do, is get the Caret position, in the Text Box, then determine it's position (based on the font size) relative to the top-left corner of the Text Field... once you've got that, you can then add it on to the position of the Text Box (in terms of screen dimensions)..

I don't do VB as I've said, so there *might* be a really easy way.. but in one of my languages, that's how I'd probably do it.

>> IM
Avatar of Mike Tomlinson
Use the GetCursorPos() API:

Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub Command1_Click()
    Dim Point As POINTAPI
    GetCursorPos Point
    Debug.Print Point.x & ", " & Point.y
End Sub
Avatar of verasen
verasen

ASKER

GetCursorPos tells mouse location. I need caret location (blinking thing) in MS Word
ASKER CERTIFIED SOLUTION
Avatar of kHSw
kHSw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Take a look at this URL from vba express :

http://www.vbaexpress.com/forum/showthread.php?t=327