PowerPoint VBA: Add a Filled Shape and Tag to Selected Slides
Question details
Add a filled rectangle with a tag to each selected PowerPoint slide using 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.
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.
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.
In PowerPoint, select one or more slide thumbnails in the left pane or in View > Slide Sorter.
Open the VBA editor with Alt+F11 or Developer > Visual Basic, then choose Insert > Module.
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
Return to PowerPoint, confirm the slides are selected, and choose Developer > Macros. Select AddShape and click Run.

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.

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.




