Some Background:
The quick background is that I am in the research stages of building an add-in for PowerPoint. My end goal is to develop a CAD Dimensioning Add-in to help expedite the creating of Engineering Presentations. We have to do a lot of "PowerPoint Engineering" where the general sizes of components are shown on simplified versions of said components created with PPT shapes or screenshots of the CAD geometry itself. But creating dimensions over and over is tedious. Each one generally consists of an arrow, 2 lines, and a text box with the dimension value.
Here is where I need some help.
(If you know how to do the following in Excel, that would work too and I will work to figure the PPT equivalent later.)
In a PowerPoint slide, while in design mode (i.e. not Slide Show Mode), I want to do the following workflow:
- In an open UserForm, the user clicks a button called "START"
- The code starts to listen for a left mouse click (LMC) out in the field of the slide itself (It should not respond to a LMC on the actual UserForm, for example if the user needs to drag the UserForm out of the way)
- Upon LMC, coordinates of the cursor are recorded as (x1,y1)
- Repeat steps 2 & 3 to record (x2, y2)
- Do stuff with these coordinates (e.g. draw a dimension between the two coordinates
I believe I can handle all of the coding with the exception step 2, which is why I am here. I am having much trouble finding a starting point. Specifically, I need help with how to listen for a LMC. In words, what envision is the following:
While Listening:
If LMC = TRUE
Do Stuff
End If
End While
But I don't have the knowledge to code the While Listening
part. I need a nudge in the right direction.
My searches have landed me on the MouseDown
event handler pages at MSDN, but in my testing, I don't think that this is what I need. Its seem as though MouseDown
is intended to start a routine when the Mouse is Down on a CommandButton in the UserForm it self.
I have also found this SO post where the only answer seemed to imply that this was not possible without going to great lengths AND the code was possible detrimental to the file itself: How to record mouse clicks in Excel VBA?. (I have no problem going to great lengths and putting in the work, but not if the resulting code has a high likelihood of doing damage as the post seems to suggest.) (Also, the OP was downvoted with no explanation, maybe someone can tell me why so I don't make the same mistake.)
You can accomplish what you are looking to do by doing the following (the bottom part may be the most helpful to you): First, Declare the following:
and the following code snippets will allow you do either click, double click, or right click:
All you need to do is change the cursor position to the coordinates on the screen. To do this, I made a new macro with the following code and assigned it to the "Ctrl+Y" button. This will tell you the coordinates of your current mouse location.