+ Reply to Thread
Results 1 to 2 of 2

Mouse X-Y Coordinates

  1. #1
    Bob
    Guest

    Mouse X-Y Coordinates

    How can I get the x and y coordinates of where the mouse happens to be at
    any particular moment on the screen?



  2. #2
    Greg Wilson
    Guest

    RE: Mouse X-Y Coordinates

    The code below will return the x- and y-coordinates in pixels as opposed to
    points. Note that it is also window based instead of worksheet based. Doing
    something with it is the challenge:

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

    Sub xxx()
    Dim pos As POINTAPI
    GetCursorPos pos
    MsgBox pos.x & vbCr & pos.y
    End Sub

    I have recently posted code that determines the position of the top-left
    corner of the worksheet in pixels and also converts pixels to points and
    compensates (albeit not perfectly) for zoom. You need to know the position of
    the top-left corner of the worksheet in pixels so that you can subtract the
    correct offsets if you are to convert to points. You can thus direct the
    cursor to a specified point within the worksheet. If you're interested:

    http://tinyurl.com/l7uog

    Regards,
    Greg


    "Bob" wrote:

    > How can I get the x and y coordinates of where the mouse happens to be at
    > any particular moment on the screen?
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1