Create shapes with VBA in PowerPoint

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


Under Customize the Ribbon tab, choose Main Tabs f#rom the list.##


Then in the below box, check Developer option and then click OK.


Security Issues

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:

          Sub insert_shape()

          End Sub


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:

Sub blue_gradient_fill()

With ActiveWindow.Selection.ShapeRange

.Fill.ForeColor.RGB = RGB(0, 75, 150)

.Fill.BackColor.RGB = RGB(0, 161, 227)

.Fill.Transparency = 0#

.Fill.TwoColorGradient msoGradientHorizontal, 1

End With

End Sub

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.

vba code example

3 thoughts on “Create shapes with VBA in PowerPoint

  1. Do you have any idea how to merge, union, subtract, and intersect two shapes via VBA? I’ve been struggling with it for hours now. Admittedly, I am not much of an expert on PowerPoint VBA but I’m not even seeing any promise that it can be done. Please prove me wrong.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s