Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.


Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

How do I use VBA code in PowerPoint

You'll find lots of useful snippets of VB or VBA code on the internet and in newsgroups, but unless you know how to get the code into PowerPoint, you can't very well use them. Here's a quick tutorial on the subject.

You may prefer to use this mini-site I created for a VB Programming session I did at PPTLive

Set security options

Before you can run VBA code, you need to set PowerPoint's security options to permit macros to run. The following steps set things up so that when you open a presentation that contains macros, PowerPoint asks whether or not to disable them.

PowerPoint 97-2003

Open a presentation or start a new one.

Choose Tools, Macro, Security

On the Security Level tab of the Security dialog box, select Medium

Click OK

PowerPoint 2007, 2010 and 2013

You'll see slight differences between the PowerPoint 2007 screens here and later versions, but the steps are basically the same.

PowerPoint 2007:
Click the Office button (the great big circular thing, upper left of the PPT screen)

PowerPoint 2010/2013/2016:

Click PowerPoint options... at the bottom of the menu that appears

Click Trust Center on the left of the PowerPoint Options dialog box, then click Trust Center Settings on right.

Click Macro Settings on the left of the dialog then choose Disable all macros with notification.

Whew. Close any open dialog boxes.

PowerPoint Mac 98-2004

You don't need to do anything about macro security in order to run macros, but it's a good idea to make sure that it's enabled. Choose PowerPoint, Preferences, General and use the Enable macro virus protection checkbox to turn the macro warning on.

PowerPoint Mac 2008

Mac PowerPoint 2008 doesn't support VBA. You're perfectly safe. And alas, perfectly unable to use VBA. Sorry.

PowerPoint Mac 2011/2016

VBA came back in Mac PowerPoint 2011. And is still there in 2016, though badly crippled. If you want to do any serious VBA coding, do it in 2011 (or in Windows PPT) then test/debug in 2016.

Start the VBA editor

The VBA editor (also called the Integrated Development Environment ... IDE to its friends) is where you'll work with VBA/macro code in PowerPoint. To start the VBA editor/IDE:

PowerPoint 97-2003

PowerPoint 2007

PowerPoint 2010/2013

Mac PowerPoint pre-2008

Use View, Toolbars, Visual Basic then click the Visual Basic Editor button on that toolbar.

Mac PowerPoint 2011

Choose Tools | Macro | Visual Basic Editor to start the Visual Basic Editor.

Add code

In the VBA editor, make sure that your presentation is highlighted in the left-hand pane.

Choose Insert, Module from the menu bar to insert a new code module into your project (project = presentation in VBAspeak). Modules are one of the several "containers" that can hold VBA code.

If your code snippet already starts with "Sub XXX()" and ends with "End Sub", simply click in the new module you just inserted and paste in the code. Otherwise, you'll have to type in "Sub XXX" (where XXX is the name you want to give the subroutine (aka "macro"). When you press Enter, PowerPoint adds the parentheses and End Sub for you automatically. Then position the cursor between the Sub XXX and End Sub lines and paste in your code.

To make sure there are no serious syntax problems with the code, choose Debug, Compile from the menu bar. If there's a problem, you'll see a message explaining (well ... explaining in a geeky, obtuse way that usually won't make any sense to you) what VBA doesn't like about the code. Click OK and the problem line will be highlighted for you. Fix it and compile again until you get no error messages.

Now click the Run button (a right-facing arrowhead icon), choose Run, Run Sub/User Form from the menu bar or press F5 to run your code.

Put it to work

Once your code's working properly, you can run it directly from within PowerPoint without having to start the VBA editor.

Choose Tools, Macros, Macros to get a list of available macros ( = subroutines, remember?) in the current presentation. Highlight the one you want to run and click Run (or simply doubleclick the one you want).

You can also view and run macros from other open presentations; choose the presentation where your macro is stored from the Macros In dropdown listbox.

You can also use Tools, Customize to create your own toolbar and assign a macro to it. This won't work reliably unless the PPT file that contains the macros is open in PPT at the same time, but it's a handy way to invoke a macro with one click rather than having to chase through the Tools, Macros menu to get there.

Note: Code that compiles may still not do what you expect it to do when you run it, or it may still produce errors. If it errors out, VBA will show you a message box that lets you either End the code or Debug it. If you choose Debug, you'll be returned to the VBA editor with the problem line highlighted in yellow so you can correct the problem.

If you want to run your code without having to load the PowerPoint file it's in every time, see Create an ADD-IN with TOOLBARS that run macros

Housekeeping hints

As you accumulate additional code snippets, you'll want to figure out where you'll store them.

You could print them, but then you'd have to re-type later (and possibly introduce errors that keep the code from running correctly).

Instead, when you see some useful-looking code, select it, copy it to the clipboard, then start Notepad (Windows) or TextEdit (Mac) and paste the code into it. Then save the file, possibly to a special folder you've created just for VB/VBA code snippets. Getting the code into PowerPoint is then a simple matter of opening the Notepad file, selecting the text and copying it into PowerPoint.

If the code turns red when you paste it into a module, the likely cause is unwanted linebreaks or other extra characters (invisible) copied from the web browser or newsgroup reading program. Delete everything between line breaks and get rid of spaces before indented items to correct this problem.

Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2016 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

How do I use VBA code in PowerPoint
Last update 02 May, 2016