Using PowerPoint Scripts & Macros

PowerPoint and other Microsoft Office programs comes with VBA, Visual Basic for Applications. VBA is an implementation of Microsoft’s event-driven programming language Visual Basic 6 and let you run scripts and macros in the popular Microsoft Office applications. VBA enables building user defined functions, automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). Office for Mac also supports VBA since PowerPoint 2008 and other Microsoft applications such as Microsoft MapPoint and Microsoft Visio have support, too.

PowerPoint Scripts & Macros

By using VBA you can write or run your own Macros and PowerPoint Scripts to make richer PowerPoint presentations with custom application code. Here we will review what is available in the PowerPoint interface to work with Macros and Scripts. This can be very handy if you plan to code your own Macros or someone shared a script that you want to run in PowerPoint.

Install Developer menu in PowerPoint 2010

To install the developer menu in PowerPoint you’d need to customize the ribbon. Right click in the PowerPoint ribbon and then choose Customize the Ribbon.

If you plan to use Macros in PowerPoint more often, it is recommended to install the Developer toolbar as a menu.

powerpoint scripts

This will add a new menu to PowerPoint with Developer buttons. We will use it to access the VBA editor but you can alternatively use Alt-F11.

This toolbar can be helpful if you plan to use developer tools, like accessing Visual Basic for Applications, run macros, configure add ins or even create a Form using controls.

PowerPoint Scripts

Let’s start inserting a new module. Here is where you will place your VBA code or scripts.

powerpoint macros

You can also import macros and scripts from file if you have the code that downloaded from Internet or someone shared by email.

If you want to insert a simple VBA code example in PowerPoint Macro, then let’s start using this simple snippet. Here we will show you how to create a random number in a shape as an Action, using Macros.

When you click on the following shape, the number will be updated with a random value between 0 and 99.

random number powerpoint

Enter the module you have created earlier and add the following subroutine.

powerpoint macro number

Now, you can assign this macro to the shape as an action. Go to PowerPoint editor and then select the shape where you want to assign the action. Now go to Insert menu and click to insert an Action.

powerpoint actions

Finally, play the slideshow and try clicking on the shape. This will update the shape text with a random value.

actions powerpoint random macro script module

It is important to notice that any macro enabled PowerPoint file should be saved as a PPTM presentation file format. This is a requirement in newer versions of PowerPoint for security concerns, especially when you download presentations from Internet. It is recommended to check the Getting Started with VBA in PowerPoint 2010 to learn more about how to start using VBA. If you want to download this free macro and script for PowerPoint, click on the following download link to download the PowerPoint example.  Random Number PowerPoint Script (2426 downloads)


5 comments on “Using PowerPoint Scripts & Macros

  1. While viewing a PowerPoint 2010 slide show, I’d like a Middle Mouse Click to completely end the show and the application. Can a macro do that? Thanks.

    1. Dear Steve.

      Yes, there are a couple of ways you can perform this.

      First, you can use the MouseDown event (see here) and the acMiddleButton bit mask to detect the middle mouse button.

      Then, using the Quit method you can completely quit PowerPoint (Office). Learn more about Quit method clicking here.

      I’d love to hear the results.

  2. What script can I use in a PowerPoint presentation to automatically print a slide to a specific printer that is not the default printer?

    1. Dear Cynthia,
      Thank you for leaving your comment. I guess the VBA script here is a good starting point to answer your question. At least it will give you an idea on how to detect if any other printer rather than the default printer is present on your computer.

Leave a Comment

Your email address will not be published. Required fields are marked *