PowerPoint Macros: How to run VBA in your PowerPoint 2016 and 2019 slides?


Last updated: October 2019. Applicable to Microsoft Office 365, 2019 and older. Windows operating Systems.

Here’s a question we got from a reader:

I have a need to automatically resize all images stored in a specific presentation I have to prepare for my management. As the slides are quite standard, this looks like something I could automate using a Macro. The thing is that I don’t find the macro recorder button in the PowerPoint development tab. Can you help?

Yes sure! There are many tasks that could use quite a bit of automation in PowerPoint such as:

  • Auto-creating periodical presentations (say quarterly reports).
  • Auto-formatting your PowerPoint slides – applying styles, fonts.
  • Working with images (resizing, adjusting to slide templates etc’).
  • Getting rid of unused slide master templates that bloat your presentation size.
  • And more…

Can i record a Macro on PowerPoint?

I would like to clarify this point, as couple of readers specifically asked for this. Microsoft PowerPoint doesn’t ship a macro recorder such as the one you’ll find in Word or Excel. Therefore,  if you want to automate PowerPoint, you’ll need to create your macro manually using Visual Basic for applications (VBA). VBA  is a relatively simple programming language used  by power users to extend Microsoft Office functionality. All that said, the process is not complicated , just follow along the instructions below.

Create a macro enabled presentation

First off,  we’ll go ahead and create a backup of  the original presentation, so you can always come back to it if needed:

  1. Open the specific presentation that you want to automate.
  2. Save your presentation using a different file name, say MyPresentationwithMacros, and make sure to pick the file format .pptm (Powerpoint Macro presentation) as your file type.

In order to move forward with your macro development, you need to able to access your VBA programming user interface. If  you don’t see the a menu called Developer which by default appears in the right side of your Ribbon, you should go ahead and enable the development menu.



Add your Macro to PowerPoint

Your next step would be to insert your VBA code snippet into a Visual Basic for Applications Project Module. Follow the instructions below:

  1. From the Ribbon, hit Developer.
  2. Then hit the Visual Basic button.
  3. The VBA editor will open up.
  4. Now, from the project tree, highlight the VBAProject entry.
  5. Now from the header menu hit Insert and select Module.
  6. Type the following code into the newly created module. This small macro adds a  new slide into the second position in your Presentation.
Sub Add_Slide()
Dim NewSlide as Slide
Set NewSlide = ActivePresentation.Slides.Add(1, ppLayoutBlank)
End Sub

Important: A word of caution here: Always ensure that you obtain your macro from reliable sources. Copying VBA code from the web is not a good idea!

  1. Before running your code, you might want to check it for errors. Go ahead and hit Debug and then select Compile VBA project.
  2. If you receive no error messages, you can go ahead and hit Save. This will update your PwerPoint macro enabled presentation.

Enable your macros

Your Microsoft Office installation might have VBA Macros disabled by default with no notification provided to the end user. If that’s the case, from the Developer tab, hit Macro Security and select Disable all macros with notification. From now on, PowerPoint will post a visible message below the Ribbon in case that your presentation contains Macros Content that was disabled by default and will specifically ask you for permission to run those Macros.

Running your PowerPoint Macro

  1. Close the VBA editor and return to your PowerPoint presentation.
  2. Back to your developer tab, hit Macros.
  3. Pick the Macro that you have just added to your presentation in the previous section.
  4. Hit Run.

Assign your Macro to a button

As you just learn, you are able to easily invoke your PowerPoint macro from the Developer tab. You can also invoke the Macro from the View tab. However, if you are interested to improve the user interaction with the Macro you can you can easily assign it to a new button in the the quick access toolbar; alternatively you can link your Macro to a Command button in your slide or in a UserForm.

Custom Macro for PowerPoint examples

Couple readers asked for some Visual basic for Applications macro examples for PowerPoint. Feel free to contact me using the contact form to discuss your specific custom Macro development requirements.

Leave a Comment: