Creating a (spotlight/mask) overlay in your PowerPoint slides automatically

Steve de Peijper
Office Productivity
3 min readMay 29, 2023

When giving presentations you might want to keep the listener focused on certain points on the slide. For this, you can use spotlights like this:

Highlighting one box

The below video shows how to use an Add-In that does this for you automatically. The add-in also has an update function, this allows you to update the newly created slides (with the spotlight). The Add-In can be found here.

Please note, autosave needs to be disabled for the add-in to work!

This video shows how to use and modify the VBA code:

The code for the overlay function can be found here.

Code walkthrough

In this paragraph, I will highlight a few parts of the code that are worth noting.

The CopyShapesAndIterat e subroutine is responsible for adding a transparent rectangle shape to the current slide and merging it with a selected shape.

Line 12: Get the currently selected shape by accessing the first shape in the `ShapeRange` of the `Selection` object of the active window.

Lines 15–18: Create a duplicate of the selected shape by using the `Duplicate` method of the `Shape` object. The duplicate shape is positioned at the same location as the original shape. This is not the case automatically when pasting on top of the same shape.

Lines 32–33: Add the duplicate shape and the rectangle to the selection by using the `Range` property of the `Shapes` collection. The selected shapes are passed as an array of shape names. This prepares for the ‘MergeShapes’ action.

Line 36: Merge the selected shapes (duplicate shape and rectangle) using the `MergeShapes` method of the `Shapes` collection.

CopyShapesAndIterate

A few notes on the update function:

16–19. Line 16–19: Copying shapes from the selected slide:
— The “selectedShapes” collection is set by assigning all shapes on the selected slide.
— A loop iterates over each shape in “selectedShapes” and adds it to the “copiedShapes” collection.

27–37. Line 27–37: Iterating over the specified number of slides:
— A loop runs from the next slide after the selected slide (selectedSlide.slidenumber + 1) to the next slide after the specified number of slides to iterate (selectedSlide.slidenumber + numSlidesToIterate).
— Inside the loop, the “selectedSlide” is updated by calling the “getslide” function and passing the loop counter “i” as the argument.
— A nested loop iterates over each shape on the current slide and prints its name using the Debug.Print statement.
— Following that, all shapes on the current slide, except the top 2 shapes, are deleted using a loop. The top 2 shapes are the overlay and the assumed shaped with the explanation!
— The top 2 shapes are then brought to the front using the ZOrder method.
— Again, all shapes on the current slide, except the top 2 shapes, are deleted using a loop. It removes the shapes twice because of scenarios where placeholders are used in templates.— Finally, the copied shapes are pasted onto the current slide using a loop and brought to the front using the ZOrder method.

Line 42–57: Definition of the “getslide” function. This is created to iterated slides by slide number, and not by index.
— The “getslide” function takes an integer argument “slidenumber” representing the slide number to retrieve.
— The function loops through each slide in the ActivePresentation.Slides collection.
— If a slide’s slidenumber matches the input “slidenumber,” it is assigned to the “result” slide object, and the loop is exited.
— The function returns the “result” slide object.

Additionally

When creating the adding I used the icons, using the below link.

Finally

This article hopefully shows how easy it is to customize/enhance PowerPoint to increase your productivity.

Do you like it? Don’t hesitate to leave claps (can go up to 50..). Thanks!

--

--

Steve de Peijper
Office Productivity

Background in BI & Advanced Analytics enjoys writing code for various applications like analyzing sporting activities, home automation, and office productivity.