I have been searching this one for a while and I am still having some issues. My end goal here is to create an Add-In for PowerPoint that allows me to create dimensions similar to a CAD package. I am developing it in Excel since I can find much more documentation on Excel VBA.
My main question, as the title alludes to, is regarding getting the screen position for drawing the actual dimension, but any feedback on other aspects of what I am trying to accomplish is welcome.
The Question:
The VBA method for drawing a line is Shapes.AddLine(beginX, beginY, endX, endY)
. The X-Y coordinates are relative to the upper-left corner of the document itself.
I found the following at http://www.mrexcel.com/forum/excel-questions/173120-mouse-events-visual-basic-applications.html:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Sub PositionXY()
Dim lngCurPos As POINTAPI
Do
GetCursorPos lngCurPos
Range("A1").Value = "X: " & lngCurPos.x & " Y: " & lngCurPos.y
DoEvents
Loop
End Sub
which has does the following:
... if you are interested in seeing the coordinates in a cell on a constant basis such as in cell A1, run the macro named PositionXY and move the mouse around.
To exit the procedure, double click any cell and then either hit Esc, Enter, or select any cell.
The issue is that the POINTAPI method gets the absolute screen position.
Is there a better way of doing this? I use dual monitors and POINTAPI seems to be returning the position relative to the top-left of the primary monitor ... I'd like to find a way where I don't have to worry about this if possible.
Thank you.