How to Use VBA Code in PowerPoint

How to Use VBA Code in PowerPoint

Visual Basic for Applications (VBA) is a Microsoft Office tool that allows users to automate tasks, create custom functions, and enhance MS Office files, including PowerPoint presentations. If you want to improve efficiency and add dynamic functionality to your slides, VBA in PowerPoint is what you might need. In this tutorial, we will explore how to use VBA code in PowerPoint, from the basics, such as accessing the VBA editor, to advanced methods, including executing scripts that optimize your workflow as a presenter.

What is VBA in PowerPoint?

VBA (Visual Basic for Applications) is a programming language built into Microsoft Office applications, including PowerPoint. VBA can teach you all you need to know about how to make a presentation dynamic, as it enables users to create macros, automate repetitive tasks, and integrate advanced functionalities into PowerPoint presentations. While many people regard Microsoft PowerPoint as an essential tool for creating impactful presentations, its default features have limitations. This is where VBA scripts are used to fill the gap, such as in the form of PowerPoint add-ins.

Unlike standard presentation templates in PowerPoint, animations, and transitions, Visual Basic for Applications provides greater control and customization, making it ideal for corporate and professional presentations requiring some kind of automation. The level of control that VBA scripts enable can help you customize & automate workflow, enabling you to decide how to start a presentation, manage content slides, and customize the way the presentation concludes.

How to Use a VBA Code in PowerPoint

To use VBA code in PowerPoint, you will have to start by accessing the VBA editor to write and manage scripts. Then, you will try using codes to optimize your workflow and see which methods best suit your needs.

Open the VBA Editor in PowerPoint

Before writing any VBA code, you need to access the VBA editor. For someone new to using VBA in PowerPoint, the basic question to get started would be accessing it. If you are wondering how I can open the VBA editor in PowerPoint, follow these simple steps:

Open PowerPoint and navigate to Developer -> Visual Basic to open the VBA Editor window.  

Note: If Developer tab not visible in the PowerPoint Ribbon, enable it by going to File -> Options -> Customize Ribbon.

Finding PowerPoint Developer Tab
Locating the Developer tab in PowerPoint’s Ribbon

Writing and Running VBA Code in PowerPoint

Once inside the VBA editor, you can create macros to enhance your presentations. Below is a simple example to automate slide transitions using VBA code.

Example: Automating Slide Transitions with VBA Code

The below script is an example of a VBA code in PowerPoint. This script automatically sets each slide in your presentation to advance after three seconds. To demonstrate this example, we will use the Tech Startup Business Development PowerPoint Template.

Step 1: To run the script given below, go to Developer -> Visual Basic to open the Visual Basic editor.

Step 2: Go to Insert -> Module, copy and paste the script below.

Sub AutoSlideShow()
	Dim slide As slide
	For Each slide In ActivePresentation.Slides
          slide.SlideShowTransition.AdvanceTime = 3
          slide.SlideShowTransition.AdvanceOnTime = msoTrue
	Next slide
	MsgBox "Slide transitions set to 3 seconds!"
End Sub
Creating a VBA code in PowerPoint for slide transitions

Step 3: Either press F5 or select Run -> Run Sub/UserForm.

Executing a macro in PowerPoint
Running macro in VBA PowerPoint

If the script includes a MsgBox, a pop-up confirmation will appear. The VBA script will now execute, applying the desired automation or modification to your PowerPoint presentation.

Macro successfully executed in a VBA-enabled PowerPoint presentation
Macro successfully executed in a VBA-enabled PowerPoint presentation

Using VBA with PowerPoint for Business Presentations

VBA code can be used to automate repetitive tasks, enhance user interaction, and optimize your PowerPoint workflow. Using VBA in PowerPoint can improve efficiency by:

  • Automating repetitive formatting tasks in PowerPoint.
  • Enhancing interactivity with navigation controls to improve productivity.
  • Integrating data dynamically (e.g., auto-updating charts and tables).
  • Standardizing presentation elements for corporate branding.
  • Improving workflow to help you focus on the content to create an engaging presentation.

We have compiled a few examples for business presentations to demonstrate the efficient use of VBA code in PowerPoint. The examples below show how you can perform various productivity-related tasks using VBA code.

1. Using VBA Code in PowerPoint for Automating Repetitive Tasks

VBA can streamline the process if you frequently update presentations with new data or slides. For example, a VBA code can automate the insertion of a company logo on every slide.

Example: Script to Automate Company Logo on Each Slide

Using the VBA Code below, you can automate the process of inserting a company logo on each PowerPoint slide.

Sub InsertLogo()
	Dim slide As slide
	Dim logo As Shape
	For Each slide In ActivePresentation.Slides
    	  Set logo = slide.Shapes.AddPicture("C:\path\to\logo.png", msoFalse, msoCTrue, 10, 10, 100, 50)
	Next slide
	MsgBox "Logo added to all slides!"
End Sub
Creating a script to automate adding company logo on slides
Script to Automate Company Logo on Each Slide

As the image below demonstrates, you can use simple VBA codes like the one above to add logos to all slides and customize branding for your corporate presentations.

Logo added to all slides via VBA code in PowerPoint
Logo added to all slides via VBA code in PowerPoint

If you have dozens of slides, this process described above can help you to save time. Otherwise, you can always insert a company logo in PowerPoint using a manual approach.

2. Enhancing User Interaction using PowerPoint VBA Code

VBA can create navigation buttons for interactive corporate presentations. Let us use an example to show you how to do this.

Example: Create Navigation Buttons using VBA Code in PowerPoint

Sub CreateNavigationButtons()
	Dim btn As Shape
	Dim slide As slide
	For Each slide In ActivePresentation.Slides
    	  Set btn = slide.Shapes.AddShape(msoShapeRoundedRectangle, 600, 500, 100, 50)
          btn.TextFrame.TextRange.Text = "Next"
          btn.ActionSettings(ppMouseClick).Action = ppActionNextSlide
	Next slide
	MsgBox "Navigation buttons added!"
End Sub
Script for navigation buttons in VBA code
Creating Navigation Buttons using VBA Code in PowerPoint

The image below shows how the script inserted a “Next” button on each slide, improving presentation navigation. This code can be modified to support a different navigation format. For example, you may create a tabbed menu slide or add support for a more sophisticated navigation using a similar approach.

Script for adding navigation buttons in PowerPoint
Successful result for script message

3. Maintaining Brand Identity with VBA Code

You can use VBA code to apply a uniform theme to integrate organizational branding and culture into presentations. In the example below, we used a VBA code to harmonize brand identity using a consistent theme across all slides, managing from the very start to end a presentation with the same branding.

Example: VBA Script to Maintain Brand Identity in PowerPoint Slides

Sub ApplyCorporateTheme()
	Dim slide As slide
	For Each slide In ActivePresentation.Slides
          slide.FollowMasterBackground = msoTrue
          slide.ColorScheme.Colors(ppBackground).RGB = RGB(0, 102, 204) 'Corporate blue shade
	Next slide
	MsgBox "Corporate theme applied!"
End Sub
PowerPoint VBA code for custom color theme
VBA code for changing slide deck theme

In corporate environments with strict brand presentation guidelines, this VBA code can help to save a lot of time.

How to Run a PowerPoint VBA Macro

Now that you know how to use VBA scripts in PowerPoint, you can use Macros to run them. 

Step 1: To enable a Macro, hit ALT+F8 on your keyboard or go to Macros from the Developer tab.

Step 2: Select a macro from the scripts you see in the window that appears and click Run. You can also edit and delete Macros from this menu.

Applying presentation theme via macro
Corporate theme applied via macro
Contextual window for running macro in PowerPoint
Running macro for custom presentation theme

How to Assign VBA Script Macros to Buttons in PowerPoint

To assign Macros to buttons, you can use PowerPoint Shapes and link them to specific Macros.

Step 1: Go to the Insert -> Shapes and insert a shape in PowerPoint.

Creating a button for macro action trigger
Inserting a button to link macro action

Step 2: Double-click within the shape and type text to assign the button a name. 

Step 3: Select the shape, go to Insert -> Action, and assign a Macro via Run Macro. Depending on the tab you use to enable the macro, you can enable macros via mouse-click or mouse hover.

How to link a macro to a button
Adding the macro to the button

Step 4: Save the PowerPoint presentation as a Macro-enabled file via File -> Save As -> PowerPoint Macro-Enabled Presentation (*.pptm).

Step 5: Switch to Slide Show mode to test the Macro. Once you click the button, the Macro will be executed.

PowerPoint macro prompt window
Prompt window for running macro in PowerPoint

The shape will execute the Macro connected to it using the method above. In the example below, we applied the blue corporate theme mid-slideshow using an action button attached to a Macro created using a VBA script. By using VBA codes like these, you can automate tasks associated with company branding or perhaps surprise your audience with something to make your presentation interesting.

50+ More VBA Ideas and Examples for PowerPoint Users

Below is a list of additional tasks and automation ideas that can be accomplished using VBA in PowerPoint. These can be used as inspiration for building your own scripts or enhancing your presentation workflow:

  1. Using VBA to delete slides in PowerPoint
  2. VBA to find all notes comments
  3. VBA to generate a document with all the PowerPoint notes
  4. VBA to remove duplicate slides
  5. VBA to clear slide notes
  6. Create a PowerPoint presentation from scratch using VBA code
  7. Using Excel VBA to copy a chart into PowerPoint
  8. Add tables in PowerPoint using VBA
  9. Export table data from PowerPoint slides
  10. Sort tables in PowerPoint using VBA
  11. Generate random text in PowerPoint with VBA
  12. Create a raffle system in PowerPoint using VBA
  13. Random number generator in PowerPoint using VBA
  14. Convert bullet points or text into a table using VBA
  15. Insert multiple pictures in PowerPoint using VBA
  16. Change the shape of an image using VBA in PowerPoint
  17. Modify or replace placeholders dynamically in PowerPoint
  18. Insert today’s date automatically using VBA
  19. Auto-update links and embedded objects in PowerPoint presentations
  20. Add APA-style references at the end of a presentation with VBA
  21. Set the active slide programmatically using VBA
  22. Add or update slide numbers with VBA
  23. Jump to a specific slide based on conditions or user input
  24. Create a countdown timer in PowerPoint with VBA
  25. Extract all text from a PowerPoint presentation using VBA
  26. Merge content from multiple presentations into one using VBA
  27. Auto-generate a table of contents slide
  28. Color-code slides or shapes based on keywords
  29. Lock specific slides to prevent edits using VBA
  30. Add audio or video to slides automatically
  31. Bulk format all textboxes or shapes
  32. Automatically resize all images on slides
  33. Save slides as images using VBA
  34. Export each slide to PDF using VBA
  35. Insert slide titles from an external file (e.g., Excel or TXT)
  36. Run conditional formatting on slide elements using VBA
  37. Highlight keywords throughout all slides automatically
  38. Add speaker notes to slides based on external data
  39. Apply a specific slide layout to all slides
  40. Batch rename shapes in a slide deck
  41. Create slide animations with VBA
  42. Track slide views during a presentation with VBA
  43. Set automatic email notifications when a presentation is opened
  44. Show a welcome splash screen before the presentation starts
  45. Automatically align all shapes or objects across slides using VBA
  46. Detect and report missing fonts in a presentation
  47. Create a custom slideshow (subset of slides) using VBA
  48. Highlight all instances of a specific word or phrase in the presentation
  49. Batch change slide backgrounds based on slide content
  50. Insert a progress bar on each slide that updates during the slideshow

FAQs

What is VBA in PowerPoint?

VBA (Visual Basic for Applications) is a programming language built into Microsoft Office, including PowerPoint. It allows users to automate tasks, create custom functions, and enhance presentations with dynamic features not available through standard PowerPoint tools.

How do I open the VBA Editor in PowerPoint?

Go to the Developer tab and click Visual Basic to access the VBA Editor. If the Developer tab is not visible, enable it via File > Options > Customize Ribbon, then check the Developer box.

Can I run VBA macros in PowerPoint without enabling macros?

No, macros must be enabled to run VBA scripts. Always save your presentation as a Macro-Enabled Presentation (.pptm) to ensure the code can be executed.

Is PowerPoint VBA supported in Google Slides?

No, Google Slides does not support VBA. VBA is a Microsoft Office feature and won’t work in platforms like Google Slides, Canva, or Zoho Show. In Google Slides, you can use Google Apps Scripts instead.

What file format should I save my presentation in if it includes VBA code?

Save it as a PowerPoint Macro-Enabled Presentation (.pptm) to ensure all your macros and scripts work properly.

Are there any risks to using VBA in PowerPoint presentations?

Yes. Macros can crash on legacy devices, and certain venues may block macros for security reasons. Always test your presentation beforehand to avoid issues.

Do I need to be an expert programmer to use VBA in PowerPoint?

Not necessarily. Even beginners can use simple VBA scripts by copying examples and testing them. However, more complex tasks may require basic programming knowledge. If you don’t have VBA-programming skills, you can get help from ChatGPT, Claude, or other LLMs to help you start out with the VBA code.

Is it possible to duplicate PowerPoint macros in Google Slides?

Not directly. PowerPoint macros use VBA (Visual Basic for Applications), which is not supported in Google Slides. However, you can extend Google Slides using Google Apps Script, a JavaScript-based language that allows automation and customization within the Google Workspace environment. While Apps Script is different from VBA, you can often recreate similar automation workflows in Google Slides with some adaptation.

Final Words

Understanding how to use a VBA code in PowerPoint can significantly enhance your PowerPoint presentations, making them more efficient, engaging, and professional. Whether you’re automating slide transitions, inserting interactive buttons, or standardizing branding, VBA offers limitless possibilities for enhancing your slides, automating tasks, and improving workflow.

PowerPoint presentations customized using VBA can be useful for use across other platforms such as in the form of Google Slides templates or other platforms like Canva or Zoho Show that enable editing and sharing PowerPoint files.

Using VBA scripts, even for advanced users with a lot of coding experience, can be a task that might require some trial and error. While VBA scripts are straightforward enough to use, a bit of testing and refinement is quite likely to ensure that your added codes and Macros don’t clash with slide elements and the overall functionality of your presentation. Not to mention, legacy devices at venues running your presentation can crash using Macros, so testing them beforehand is always a good idea to avoid any inconvenience before your session begins.

Developers commonly use VBA codes to make PowerPoint add-ins, adding functionalities in PowerPoint that aren’t originally present. However, if there is a feature or customization that you are looking for that isn’t present in PowerPoint, it might be time to brush up on your coding skills and try your hands at using VBA codes in PowerPoint.

Macro, Microsoft PowerPoint, PowerPoint Tools
Filed under