0

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.

Community
  • 1
  • 1
Saladsamurai
  • 587
  • 2
  • 5
  • 11
  • What exactly are you trying to accomplish, though? – Steve Rindsberg Jun 23 '15 at 20:23
  • @SteveRindsberg - I would like to eventually have a dimension button on a ribbon. When clicked, a user-form would open and you would select a dimension type and then you would click 2 points on the worksheet (excel) or slide (PPT) and it would 'drop' a dimension. You can then edit the value of the dimension (a text box). See the dimensions here for example: https://forum.solidworks.com/servlet/JiveServlet/downloadImage/2-259726-26037/450-300/untitled.PNG. Note that I do not need the routine to measure the actual distance between selected points. The value will be entered manually. – Saladsamurai Jun 24 '15 at 15:09
  • I suppose my question really just boils down to this: given the method 'Shapes.AddLine(beginX, beginY, endX, endY)', how can I pass 'beginX,Y' and 'endX,Y' back to the method as mouse clicks? – Saladsamurai Jun 24 '15 at 16:25
  • The posts at http://www.mrexcel.com/forum/excel-questions/689070-question-about-cursor-x-y-pixel-position-excel-sheet.html by John_w look promising. – Saladsamurai Jun 24 '15 at 19:10

1 Answers1

0

The methods ActiveWindow.PointsToScreenPixelsX(0) and ActiveWindow.PointsToScreenPixelsY(0) address the question asked.

There are more items I need help with, but they warrant more research and their own questions. Thank you.

Saladsamurai
  • 587
  • 2
  • 5
  • 11
  • Search SO for those methods; ISTR that there was a discussion of them not too long ago. – Steve Rindsberg Jun 25 '15 at 15:31
  • @SteveRindsberg - Thank you for your reply. In what context did you see them discussed? I believe that I understand them and that they answer the OP (my) question. I will be accepting this answer once the 24 hour period to accept your own answer elapses. I am moving onto the listening part of the program if you have any interest in taking a look. http://stackoverflow.com/questions/31055297/powerpoint-or-excel-vba-capture-coordinates-of-mouse-click – Saladsamurai Jun 25 '15 at 16:05
  • Here are a couple of the discussions: http://stackoverflow.com/questions/14635383/ms-powerpoint-how-to-convert-a-shapes-position-and-size-into-screen-coordinate and http://stackoverflow.com/questions/20786012/how-to-deduce-the-slide-ppt-position-of-a-shape-from-the-screen-position-of-the – Steve Rindsberg Jun 26 '15 at 15:00