I'm exploring a new idea related to my original post.
In PowerPoint edit mode, it is a simple task to insert/shape/rectangle. When inserted, the rectangle is the active selection.
I know I can add a rectangle with VBA:
myDocument.Shapes.AddShape Type:=msoShapeRectangle, Left:=50, Top:=50, Width:=150, Height:=300
However, I want to use (or copy) the UI-friendly code that allows the user to place/size the rectangle with the mouse.
Is there a VBA hook to perform this action? Trigger the 'insert rectangle' action which then gives control to the user to insert the rectangle; then return control to the active sub?
My idea is that if I already have the original image selected before I run the macro, I can grab the image x,y,h,w; then trigger the insertion of the rectangle, and grab the rectangle x,y,h,w. Then apply math to crop the original picture.
Just not sure how to use/hook the built-in 'insert rectangle' code that uses mouse control for size and placement.
CodePudding user response:
Using the CommandBars command, you can run most controls:
Application.CommandBars.ExecuteMso ("ShapeRectangle")
To find the control names to use with CommandBars, you can download Microsoft's documentation from this GitHub page: Office Fluent UI Command Identifiers
Some programmers also resort to using SendKeys, but that's a less reliable method.