Using PowerPoint Scripts & Macros
Last updated on May 20th, 2024
PowerPoint and other Microsoft Office programs come with VBA, Visual Basic for Applications. VBA is an implementation of Microsoft’s event-driven programming language, Visual Basic, and it lets 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.
We will review the PowerPoint interface’s capabilities for working with Macros and Scripts. This can be very handy if you plan to add scripts to PowerPoint or code your own Macros, or if someone shares a script with you to perform a specific task in PowerPoint.
How to Install Developer Menu in PowerPoint
To get started with VBA scripting in PowerPoint you must install the Developer menu. This is done by customizing the PowerPoint 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.
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 (Example to Generate a Random Number)
Let’s start inserting a new Module. Here is where you will place your VBA code or scripts. For the sake of this demonstration, we will add a simple script to PowerPoint to generate a random number and show it in the PowerPoint Slide.
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.
Enter the module you have created earlier and add the following subroutine.
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.
Finally, play the slideshow and try clicking on the shape. This will update the shape text with a random value.
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.
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 (2435 downloads )
Just to sign up for newsletter
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.
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.
What script can I use in a PowerPoint presentation to automatically print a slide to a specific printer that is not the default printer?
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.