Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: cursor position

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is there anyway to know what the current position the cursor is?

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi
    I don't know which context you are looking for...
    This is a windows screen cursor position.
    Position 0 will be at the upper left hand corner of the screen, not the worksheet..
    Ex NOT Cell A1
    The only way I know how to capture the cursor location in the actual app would be to use an image box and capture the coordinates via the image's mouse move event.

    Tom

    Option Explicit

    Type POINTAPI
    x As Long
    y As Long
    End Type

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

    Dim z As POINTAPI ' Declare variable

    Sub GetCursor()
    Range("A1") = "X = "
    Range("A2") = "Y = "
    Do
    GetCursorPos z
    Range("B1") = "x: " & z.x ' Get x co-ordinets
    Range("B2") = "y: " & z.y ' Get y co-ordinets
    DoEvents
    Loop
    End Sub

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-13 11:48, TsTom wrote:
    Hi
    I don't know which context you are looking for...
    This is a windows screen cursor position.
    Position 0 will be at the upper left hand corner of the screen, not the worksheet..
    Ex NOT Cell A1
    The only way I know how to capture the cursor location in the actual app would be to use an image box and capture the coordinates via the image's mouse move event.

    Tom

    Option Explicit

    Type POINTAPI
    x As Long
    y As Long
    End Type

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

    Dim z As POINTAPI ' Declare variable

    Sub GetCursor()
    Range("A1") = "X = "
    Range("A2") = "Y = "
    Do
    GetCursorPos z
    Range("B1") = "x: " & z.x ' Get x co-ordinets
    Range("B2") = "y: " & z.y ' Get y co-ordinets
    DoEvents
    Loop
    End Sub
    Just to Add to DK and Toms
    Replace the Do with this;


    MsgBox "To stop the prgm just select A1", vbSystemModal
    Do Until ActiveCell.Address = "$A$1"


    This will give you the readings...then when
    you want the prgm to Stop just place your
    cursor @ A1.


    Kind Regards,
    Ivan F Moala From the City of Sails

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •