VBA & Macro Problems

PowerPoint VBA: Add a Filled Shape and Tag to Selected Slides

Kushani NimanthikaKushani Nimanthika Nov 14, 2026 870 views

Question details

Add a filled rectangle with a tag to each selected PowerPoint slide using VBA.

Add a Filled Shape and Tag to Selected Slides with PowerPoint VBA
Product
Microsoft PowerPoint
Device & OS
not provided
Scenario
A user wants to create a shape outside each selected slide, set its fill color, and attach a tag.
Observed behavior
The macro should add the rectangle, apply the fill color, and store the tag in the shape's Tags collection.
Before you start

Open the presentation in a version of PowerPoint that supports VBA and select the target slides in the thumbnail pane or Slide Sorter. Save the presentation as a macro-enabled .pptm file if you want to keep the macro.

Solution 1Recommended

Run a VBA macro to add a filled, tagged shape to selected slides

Use this macro to add a maroon rectangle just outside the right edge of each selected slide.

Tags belong to the Shape object, not its Fill object. The macro sets the fill through the shape's Fill property and adds the tag through its Tags collection.

The rectangle's left position is based on the presentation's slide width, so it is placed outside the slide regardless of the slide size.

1
Select the slides

In PowerPoint, select one or more slide thumbnails in the left pane or in View > Slide Sorter.

2
Insert a VBA module

Open the VBA editor with Alt+F11 or Developer > Visual Basic, then choose Insert > Module.

3
Paste the macro

Paste this code into the module: Sub AddShape() Dim oSld As Slide Dim oSh As Shape If ActiveWindow.Selection.Type <> ppSelectionSlides Then MsgBox "You need to select slides!" Exit Sub End If For Each oSld In ActiveWindow.Selection.SlideRange Set oSh = oSld.Shapes.AddShape( _ Type:=msoShapeRectangle, _ Left:=ActivePresentation.PageSetup.SlideWidth + 10, _ Top:=50, Width:=100, Height:=200) With oSh .Fill.ForeColor.RGB = RGB(128, 0, 0) .Tags.Add "TOM", "JERRY" End With Next oSld MsgBox "Shapes added" End Sub

4
Run the macro

Return to PowerPoint, confirm the slides are selected, and choose Developer > Macros. Select AddShape and click Run.

Run a VBA macro to add a filled, tagged shape to selected slides
Adjust the shape: Change RGB(128, 0, 0) for a different fill, or edit the tag name and value in .Tags.Add. Position and size values are measured in points.
Free Microsoft Office alternative

Edit presentations with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and support for Microsoft Office formats, making it easy to move existing files into WPS. Use PowerPoint for the VBA macro in this article; WPS does not fix PowerPoint-specific VBA issues.

Create and edit presentation shapes in a familiar interfaceOpen and edit Microsoft PowerPoint PPT and PPTX filesWork with Word and Excel formats alongside presentationsGet started with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why can't I add a tag to a shape's fill?

The Tags collection belongs to the Shape object. After creating the shape, use a statement such as oSh.Tags.Add "TOM", "JERRY" rather than trying to add the tag through oSh.Fill.

How do I place the rectangle outside the slide?

Set the shape's Left position beyond the slide width, for example ActivePresentation.PageSetup.SlideWidth + 10. The value is in points.

How can I change the rectangle's fill color?

Edit the RGB values in .Fill.ForeColor.RGB = RGB(128, 0, 0) in the VBA module. Each RGB component can range from 0 to 255.

Why does the macro ask me to select slides?

The macro checks for a slide selection before using Selection.SlideRange. Select slide thumbnails in the left pane or in View > Slide Sorter, then run the macro again.

Which file format keeps the macro in the presentation?

Choose File > Save As and select PowerPoint Macro-Enabled Presentation (.pptm). Only enable macros when you trust their source.