?
Solved

Get screen coordinates of cursor in MS Word

Posted on 2005-03-27
6
Medium Priority
?
689 Views
Last Modified: 2008-03-17
I need to get the x,y screen pixel coordinates of the cursor (also known as Caret) in MS Word. Anyone know how?
0
Comment
Question by:verasen
[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
6 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13642206
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 ?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13642443
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
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13642444
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:verasen
ID: 13645985
GetCursorPos tells mouse location. I need caret location (blinking thing) in MS Word
0
 
LVL 2

Accepted Solution

by:
kHSw earned 750 total points
ID: 13650467
Check out the documentation about Selection.Information.

You can retrieve the horizontal and vertical position using:
Selection.Information(wdHorizontalPositionRelativeToPage)
Selection.Information(wdVerticalPositionRelativeToPage)

0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13655067
Take a look at this URL from vba express :

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Six Sigma Control Plans
Progress

762 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