Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 5 of 5

Thread: Getting X Y coordinate of Cursor in VBA

  1. #1
    Join Date
    16th March 2005
    Posts
    3

    Getting X Y coordinate of Cursor in VBA

    Is there a VBA routine the returns the current X Y coordinates of the cursor ?
    Or how do I write a macro to create a drawing object at the current cursor position ?

    Neil P

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Getting X Y coordinate of Cursor in VBA

    Hi Neil,

    Can you explain a little more on what you are trying to do.

    It maybe possible to get the values but I think the type of units (points/twips/pixels) returned varys.

    Cheers
    Andy


  3. #3
    Join Date
    16th March 2005
    Posts
    3

    Re: Getting X Y coordinate of Cursor in VBA

    Hi Andy,

    Thanks for responding.

    I have a set of macros that automatically create drawing objects in worksheet - lines, rectangles, text boxes etc. I want to be able to move the cursor over part of the drawing and have a macro that automatically creates a drawing object at the location of the cursor (eg I might use the OnKey event to draw a rectangle at the cursor location if the user hits the R key).

    I havent been able to find any property or function that returns the current XY position of the cursor relative to the top left hand corner of the worksheet (not the screen) - in any units.

    Thanks for your help on this,

    Neil

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Getting X Y coordinate of Cursor in VBA

    Hi,

    This is going to take some pretty complex API code, which I don't have to hand.

    Here is an example of getting the Cursors X and Y values in pixels.
    VB:
    Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 
    Type POINTAPI 
        x As Long 
        y As Long 
    End Type 
     
    Sub CurosrXY_Pixels() 
         
        Dim lngStatus As Long 
        Dim typWhere As POINTAPI 
         
        lngStatus = GetCursorPos(typWhere) 
        MsgBox "x: " & typWhere.x & Chr(13) & "y: " & typWhere.y, vbInformation, "Pixels" 
         
    End Sub 
    
    
    You will need to determine the position of the Excel application on the desktop, the workbooks position within the application in order to start the shape at the cursors position.

    I don't know how comfortable you are with this type of VBA coding.
    It's not what I usually do for sure!

    It may be possible to tackle this from a different angle if you can share an example workbook.
    Have a look at my clocks example. Especially the one that follows the cursor around.

    Cheers
    Andy


  5. #5
    Join Date
    16th March 2005
    Posts
    3

    Re: Getting X Y coordinate of Cursor in VBA

    Thanks Andy !!. I'll give that a try.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Geographic Coordinate Data Types / Formats
    By parnuna in forum EXCEL HELP
    Replies: 8
    Last Post: February 21st, 2008, 08:31
  2. Coordinate Specific Ranges Across Worksheets
    By caliskier in forum EXCEL HELP
    Replies: 3
    Last Post: January 24th, 2008, 09:36
  3. cursor behind text (F2)
    By Chefke in forum EXCEL HELP
    Replies: 3
    Last Post: June 19th, 2006, 16:22
  4. Highlight row of where cursor is
    By ctg in forum EXCEL HELP
    Replies: 1
    Last Post: April 8th, 2005, 23:49
  5. VBA: Cursor Should not go to some range ? How
    By s_u_resh in forum EXCEL HELP
    Replies: 5
    Last Post: November 29th, 2003, 03:48

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
  •  
porno