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.
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
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
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
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.
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.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
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
Thanks Andy !!. I'll give that a try.
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks