If you are not good at coding, then don’t worry, this post is pretty simple, but could save you hours of work in the long run if you use a lot of repetitive shapes in PowerPoint
Show the Developer toolbar
Click on File and then Options
Click on Customise ribbon
Then in the below box, check Developer option and then click OK.
Click the Macro Security button to specify which macros can run and under what conditions. Although rogue macro code can seriously damage your computer, security conditions that prevent you from running helpful macros can limit your productivity. Macro security is a fairly complex and involved topic that you should study and understand if you work with PowerPoint macros.
For the purposes of this blog, be aware that if the Security Warning: Macros have been disabled bar appears between the ribbon and the worksheet when you open a workbook that contains a macro, you can click the Enable Content button to enable the macros.
Also, be aware that, as a security measure, you cannot save a macro in the default PowerPoint presentation format (.pptx); instead, you must save the macro in a file with a special extension, .pptm
Adding the code
Click on the Developer tab and then on Macros
In the macro name box type “insert_shape”. Then click on Create
Visual basic will then open. A new module will be created “module1” automatically.
The following code will be inserted automatically:
In between the two lines type the following code.
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddShape Type:=msoShapeRectangle, _
Left:=50, Top:=50, Width:=100, Height:=200
Click on the run button to test the code. A rectangle should be created on the slide.
You can then create another macro called blue_gradient_fill with the code as follows:
.Fill.ForeColor.RGB = RGB(0, 75, 150)
.Fill.BackColor.RGB = RGB(0, 161, 227)
.Fill.Transparency = 0#
.Fill.TwoColorGradient msoGradientHorizontal, 1
For this code to work, you need to click on the newly created rectangle, and then click on the run button. Note occasionally, especially with gradient fills, sometimes you need to run them twice! Office bug, I think!
Have a look at the presentation attached. I have added another example to the code green_gradient_fill.