How to use VBA in PowerPoint: A beginner’s guide

  • Written by: Jamie Garroch
  • Categories: PowerPoint productivity , Presentation technology
  • Comments: 45

vba powerpoint presentations

Here at BrightCarbon we’re always looking for new ways to improve our own PowerPoint productivity and then share that knowledge with the presentation community (that includes you, by the way!). One of the ways we do this is by using VBA code to automate and extend the functionality of PowerPoint. We publish  free PowerPoint VBA code snippets here in our blog for you to use and also offer a PowerPoint automation service . This article explains how to grab the code from our articles and use it in your PowerPoint project, so that you can take your productivity to the next level!

What is VBA?

Visual Basic for Applications (VBA) is a programming environment for Microsoft Office applications. It’s included with your installation of Office by default  ( unless your system administrator has deactivated it ) . PowerPoint VBA provides you with a way to do one of two things   using macros and add-ins:  

  • A utomate  PowerPo int:   If you ever find yourself repeating the same task over and over again, VBA could be your new best friend.  Let’s say you have 100 slides and you need to unhide all hidden objects  across all those slides . That could take you  many  eye-straining minutes, but with a PowerPoint VBA it takes around a  second.
  • E xtend  PowerPoint :   Sometimes PowerPoint doesn’t have the feature you need  to complete your task . As an example, if you end up deleting default layouts from a template, there’s no  easy  way in PowerPoint to get them back. This article includes PowerPoint VBA code to do just that!

How to open the VBE (Visual Basic Editor)

Getting to meet your VBA friend is very simple. With PowerPoint open and at least one presentation file open, press  Alt+F11 * on your keyboard. This will open the VBE (Visual Basic Editor):  

PowerPoint VBE No Modules

*If for some reason Alt+F11 isn’t mapped on your keyboard you can right click anywhere on the ribbon, select  Customize the Ribbon…  and in the window that appears, tick the  Developer Tab  check box over on the right hand side before clicking  OK  to close the window. Now you can click the  Visual Basic  button within this tab:  

PowerPoint Developer Tab Visual Basic

Adding PowerPoint VBA code  

To add some VBA code, you need a container to put it in so go ahead and click  Insert  from the menu and then select  Module :  

PowerPoint VBE Insert Module

You now have a module ready to paste the VBA code into  from one of our blog articles :  

PowerPoint VBE Module Inserted

Copy the VBA code from  the required blog article  by double-clicking on it and then paste it into the  Module1  window above.  Here’s a very simple example of some code  to display a message dialogue :

You should now see something like this:  

PowerPoint VBA

Because this code is just a single  Sub  procedure called  HelloWorld , it’s referred to as a macro.  

Running  the PowerPoint VBA macro  

Now you have the macro in your presentation you can use  Alt+Tab  to return to the more familiar PowerPoint window. From here, the macro can be run by pressing  Alt+F8  on your keyboard  (or b y  clicking the  Macros  button in the Developer tab)  which opens a window containing a list of available macros:  

PowerPoint VBA

Security Soup

The first time you add VBA code to a file, Microsoft assumes that it is safe because you added it. As soon as you save, close and reopen the file, Microsoft doesn’t know that it’s your code so it will disable it by default. You can tell the Office app to allow your code to run either by signing it with a digital certificate (beyond the scope of this article) or by lowering the security setting for the app. You can do this in PowerPoint by clicking File / Options / Trust Center / Trust Center Settings / Macro Settings and selecting this option shown below:

VBA Macro Settings

Saving your file  

vba powerpoint presentations

Once you ’ve added  VBA code  to  your presentation, PowerPoint will  ask you to save it as a  pptm  file  (the ‘m’ stands for macro)  instead of the more  familiar  pptx  format .  You can go ahead and do this to  either  keep a n archive  copy of your  code-enabled  project  or   to  create your personal macro library.  

If you want to distribute your  presentation,   it’s advisable to   save  it  using the familiar pptx format so that  your  recipients don’t see lots of verbose  security  messages  when opening  pptm  files!  

Y ou can  make  your file saveable as a standard presentation again  by  right – click ing  on  each   code module in the  project explorer pane , clicking  Remove   ModuleX …   and either click  Yes   (if you want to keep a backup of the modules independently of your presentation)  or  No   when  asked if you want to save the module before removing it :  

vba powerpoint presentations

Now your presentation doesn’t include any code and you can save it as a pptx file.  

So, there you have it.  You now know how to open the VBE, insert a PowerPoint VBA code module, paste code into it, run the macro and save the file in either pptm  or pptx formats. All you need is a cool macro to make your daily life even easier. Keep checking in with our blog for more useful macros – like this one on restoring default slide master layouts!

Got something extra you’d like PowerPoint to do?

Check out our PowerPoint automation service which provides you with a custom solution to your specific needs.

vba powerpoint presentations

Jamie Garroch

Principal technical consultant, related articles, powerpoint picture placeholder choice.

  • PowerPoint productivity

As the saying goes, a picture speaks a thousand words. PowerPoint offers you multiple image sources to help you create your latest presentation masterpiece, but it isn't very consistent in how it presents them to you. Let's fix that!

vba powerpoint presentations

How to consistently brand graphs and charts across Microsoft Office

  • PowerPoint design / PowerPoint productivity
  • Comments: 1

How do you make sure that your graphs and charts have consistent branding across Excel, PowerPoint and Word? Learn how to create and use custom templates that support your brand identity across Microsoft Office.

vba powerpoint presentations

Changes to VBA Macro Security in Microsoft 365

  • Presentation technology / Industry insights
  • Comments: 2

You can do some really cool things in Microsoft Office with just a few lines of Visual Basic for Applications (VBA) - from creating your own custom formula in Excel to correcting branded content in PowerPoint to merging address data for a mail campaign in Word. And sometimes you need to share that VBA solution with colleagues and clients, via the Internet. A change that Microsoft rolled out at the end of March 2022 tweaks the process required by Windows users to gain access to this active content.

vba powerpoint presentations

very simple, very explicit, very good help for a beginner vba programmer in powerpoint. Thanks

great resource, thanks. I’ve used VBA for years in MSaccess, and this is a good refresher for me.

I am trying to make a ppt file that loops until stopped. then I save it as a video. the ppt ran and looped continuously. Once recorded as video it stopped looping. do you have code to make ppt work when in video format

Hi Charles. As soon as you export a PowerPoint deck as a video all the PowerPoint functionality is removed as the file is magically transformed into an MP4 file, without VBA (sob sob). The only way to make the video loop is to use the looping feature of your video player.

Yeah, your best off recording a screen capture of the presentation running, then cutting it so it loops perfectly.

You can convert the video into gif file so that it will loop

Hi Jamie, thanks for the clear into, I am very new to this so that really helps. I am trying to develop a VBA macro that looks for the left hand mouse key being pressed and held down for more than two seconds whilst over a shape in slideshow mode. Once this is satisfied (i.e. two second press) for it then to hyperlink or take the user to a specified slide or even the next slide worst case.

I realise there is an automated/ built in feature (Action) that does this type of thing for a mouse click or mouse over but I really need a “long press” to activate if possible.

Any help appreciated.

Hi Simon and thanks for a great question. What you’re looking to do is pretty complex because VBA doesn’t natively support mouse actions in the PowerPoint slide show window. But, it is possible to use a Windows API (hence no Mac compatibility) called GetAsyncKeyState to gain access to mouse button click events. I had a look at this and quickly ran into a brick wall because an action link to a macro in slide show mode (Insert / Action / Mouse Click / Run macro) fires on the mouse up event, not mouse down. That means any corresponding VBA timer code can’t run until after the user releases the button and hence too late to detect if it was held down for two seconds. Maybe something could be done with the mouse over event to simulate what you need to achieve? Another approach could be to use the mouse down event on an invisible userform although that is also getting very involved with multiple Windows APIs. Depending on what you’re trying to do, you could also start the timer on click one, change the colour of the clicked shape and show countdown text before reverting to the original colour. If the user clicks a second time before the time expires, then the hyperlink is fired.

Valuable app

Hello I have a question:

Private Sub CommandButton2_Click() ActivePresentation.FollowHyperlink _ Address:=”http://192.168.16.49/?OUT1=ON”, _ NewWindow:=False, AddHistory:=False ActivePresentation.SlideShowWindow.View.GotoSlide (2)

Now it opens Chrome. but how can i make it that it opens te address en afther that shut down chrome.

Hi Tom. Your example should open the default browser at the URL specified by the Address parameter. For more information on the FollowHyperlink method, see this Microsoft documentation: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.followhyperlink

Thank you very much! It’s exactly what I needed.

I have tried using your randomizing macro with a powerpoint – I must be doing something wrong, because it isn’t putting the slides in random order. Please advise! I copied the macro exactly (using cut & paste), and thought I was following all the directions here for how to use it in the powerpoint. But, no random presentation of the slides. Boo hoo!

Hi Marya. Let’s check that VBA is installed and enabled on your machine. Can you add the following macro to the VBE project (just below the existing one) and try to run it from the PowerPoint window using Alt+F8?

Sub CheckVBA() MsgBox “it’s working” End Sub

Make sure the quotes are the straight type.

I am trying to format my title page so that the number displayed is equal to the linked slide and updates automatically wherever the slide is moved. For example “about us” is on slide #5 and linked, so it goes to slide 5 when you click on the word. I need the number (in a separate text box) to update automatically to the slide number location that the link goes to.

Hi Mary and thanks for the question. It looks like you’re interested in some kind of automated agenda slide builder. That’s a fair bit of code to create and quite complex as it needs to handle events from PowerPoint to detect when slides have moved. It could be possible to write a simpler macro which you run manually each time you want to update that title page. You’d need start by finding a way to identify which objects are your numerical indicators. For example, if you named your objects in the selection pane (Alt+F10) “Agenda Link”, then is simple macro could be a starting place for you: Sub UpdateAgendaNumbers() Dim oSld As Slide Dim oShp As Shape Dim LinkedSlideIndex As Long On Error Resume Next For Each oSld In ActivePresentation.Slides For Each oShp In oSld.Shapes If oShp.Name = “Agenda Link” Then If oShp.ActionSettings(ppMouseClick).Action = ppActionHyperlink Then If oShp.HasTextFrame Then LinkedSlideIndex = Split(oShp.ActionSettings(ppMouseClick).Hyperlink.SubAddress, “,”)(1) oShp.TextFrame.TextRange.Text = LinkedSlideIndex End If End If End If Next Next End Sub

Great wealth of information. Have never used macros before but was looking to use them to help with this situation. At work we use Work Orders (created in Power Point) and are looking to include a sequential number to them (print 50-100 copies of one slide with the numbers) and if possible would like the number to continue from the last printed number…been trying to find some code to help but not having much luck possible partly due to being new to macros

That’s definitely something we could help design for you Joshua. If you’d like to discuss further, please click the Contact button at the top of this page.

I tried this changing the font color of text within the textbox. I used this to change the font color on a mouse over:

Public Sub GraphicHover(ByRef oGraphic As Shape)

oGraphic.TextFrame.TextRange.Font.Color.RGB = RGB(0, 130, 202)

and it works just fine. But, when I move the mouse off the text box, onto the invisible rectangle with this code attached to the mouseover event, it doesn’t change the text color back to it’s original color and remains the color I changed it to mentioned above. I know the mouseover event is being triggered because I checked “Highlight when mouse over” and I am seeing the highlight on the invisible rectangle:

Public Sub ResetGraphicHover(ByRef oCover As Shape) Dim oSld As Slide Dim oShp As Shape Set oSld = oCover.Parent For Each oShp In oSld.Shapes With oShp.TextFrame.TextRange.Font.Color If .RGB = RGB(0, 130, 202) Then .RGB = RGB(121, 135, 156) End With Next End Sub

Any clue where my ResetGraphicHover is failing?

Hi Dave. I took your code and it works for me. You could add a debug line after the For Each… line in the rest macro to check that (a) it’s firing and (b) which shapes are being looked at on your slide. To do that, add this:

Debug.Print oShp.Name

After you run the slide show, check the output in the VBE Immediate pane (Ctrl+G to toggle it).

Hi I am creating an interactive game (matching cards or concentration) in PowerPoint. If the 2 cards match, I need a pop-up text box to appear. If the 2 cards do not match, I need a sound to play.

I understand I need programming to make this happen. Please help or give alternative ways to achieve this. Thanks.

Hi Tammy. Have a look at this article which will help you: https://www.brightcarbon.com/blog/powerpoint-memory-game/

Hi Producer I will like to get comments on macros you can make available to me. Beautiful. I am using this approach frequently to make offline projects. Thanks. S. Fas

Excellent!!! Thank you!

You’re more than welcome Nataša!

Thank you! Is there any option to replace a font in the entire presentation for a specific character. Let’s say, I would like to change font only for dots in the deck but I would like to keep the rest in the original font. Any idea please? Thank you so much!

Hi Jan. You might be able to use the Replace Fonts feature found in the Home tab of PowerPoint under the Replace menu at the far end of the ribbon. If you need to use VBA then set up a nested loop to iterate all shapes within all slides and then use the oShp.TextFrame2.TextRange.Font object to change the font.

Exellent explenation. so beutiful. I am creating an interactive e learing quiz. Thanking you.

Hello! I have a client who’s interested in using tagging to help create searchable content within slides. For example, they have four different categories for slide content across multiple presentations (Overview, Market, Product, Country). I’d like to assign a different shape to represent each of the four categories, where a blue square might represent Overview slide content. Then, when someone uses the keyword “Overview” to search for overview content (on Teams or SharePoint), these slides are easily identified. Is this something that’s possible with VBA code?

Hi Linda. That’s a very good question! Given the need is to search via SharePoint, VBA probably won’t help here as the PowerPoint file needs to be opened for VBA to examine its content. I have a sneaking suspicion that if you add keywords in the Tags field under File / Info that SharePoint may use this. But, that’s at the file level rather than the slide level. We have a PowerPoint add-in called ShowMaker that might be of interest as it allows you to add category metadata to slides and then the presenter can use that to filter the deck and export the required content. You can find an overview of it here: https://www.brightcarbon.com/showmaker/ and we could set up a demo if you’re interested (please use the Contact button at the top of this page if that’s the case).

I’ve just created an elearning package in PowerPoint using VBA , I didn’t realise it could sum up text boxes within PowerPoint to mark the qualification at the end. Also used AWS text to speech over the top of the learning . Looks great

Sounds like a fun and successful project Stu! Thanks for sharing 🙂

I have a bit of a tricky one but hoping it is possible to do with VBA. We offer training services to multiple clients that can be customized but the majority of training is consistent from one client to the next (main changes are the slide masters/formatting and addition/removal of certain sections).

What we want to do is create one master (or multiple) training document(s), and then use VBA’s to link it to the client specific PowerPoint. We want to link the master rather than using the “reuse slide” command so that if we update one file the other will automatically update as well.

Not sure if it matters, but our company uses sharepoint as storage

Hi Dave and thanks for a great question. VBA is an excellent solution for automating a manual process. In general, if a person can perform a task manually via a sequence of pre-defined steps then VBA can do it automatically, faster, and with less chance of mistakes for something done many times. We’d be happy set up a call to discuss your needs further and see what could be automated with VBA. If that’s of interest, please use the contact button at the top of the page and mention my name in the form.

PP does not seem to have the record macro feature. To write vba code in PP by someone who only worked with vba in excel, would require some prior knowledge. Is there a summary of the most common objects, methods etc to refer to?

Hi Reef. You’re correct that there’s no VBA macro recording feature in newer versions of PowerPoint. The best place to start learning is by purchasing a book (there’s one called “Mastering VBA for Microsoft Office 365” on Amazon or reading the extremely exciting Object Model documentation from Microsoft: https://docs.microsoft.com/en-us/office/vba/api/overview/powerpoint/object-model

Hi Greeting I had made a game in power point using VBA codes. At last it generate a report every time a candidate conduct the game . My requirement is to generate result in same excel sheet after conducting the game. Like Row 1 player 1 result Row 2 player 2 result I need your help Regards

Hi Asheesh. It’s possible to use VBA to get PowerPoint to “talk” to Excel (and other Office apps) but it’s a bit complicated to mention in a comment here. We’d be happy to help if you’d like a quote or if you want to try yourself you could start with this: Set oXL = CreateObject(“Excel.Application”) and have a look at some online examples. I’d also recommend the book “Mastering VBA for Microsoft Office 365” available from Amazon.

If there are two colors of font in the textFrame, how to change the font of one color through VBA?

Hi Bruce. You could either iterate through the Characters collection of the TextRange2 object or the Runs collection which returns all of the TextRanges with the same style. Example: ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Runs(1).Font.Fill.ForeColor.RGB

Hi – can you help, please?

How can I change the font color and size of the message box? What code will work and where will I put it? Creating an interactive game in powerpoint. Thank you!

—– Sub Correct() Points.Caption = (Points.Caption) + 10 Output = MsgBox(“Your answer is correct, well done!”, vbOKOnly, “Correct Answer”) ActivePresentation.SlideShowWindow.View.Next End Sub

Sub Incorrect() Points.Caption = (Points.Caption) – 5 Output = MsgBox(“Your answer is incorrect.”, vbOKOnly, “Wrong Answer”) ActivePresentation.SlideShowWindow.View.Next End Sub

Sub Reset() SlideLayout.Points.Caption = 0 ActivePresentation.SlideShowWindow.View.Exit End Sub ———-

Thanks for your explanation.

Hi Jamie, Is there any way to keep my macro save in a file so I can utilize on any other PPTs equivalent as.normal.dotm for Word, .xlam(add-in) for Excel.

Hi Anurag. Thanks for the question and Happy New Year! The best way to do this would be to export your project as a ppam and activate it as an add-in via the PowerPoint add-ins UI. Save your ppam in %AppData%\Microsoft\AddIns and then in the Windows PowerPoint Developer tab, click PowerPoint Add-Ins and add your ppam from there. If you’re not code-signing your VBA project, you may need to adjust Trust Centre settings. You could optionally build an EXE/MSI installer package for Windows and PKG for macOS, although that is a more complex topic.

Join the BrightCarbon mailing list for monthly invites and resources

Thank you for today’s PowerPoint productivity masterclass. I’ve learned so much from BrightCarbon when it comes to PowerPoint. If there isn’t a BrightCarbon fan club already, I’ll be happy to start one! Kimm Babo Wegmans Food Markets

vba powerpoint presentations

pptbliss.com

VBA PowerPoint Design: Automate Presentations with Macros

Trish Dixon

Are you looking to automate PowerPoint design tasks using VBA (Visual Basic for Applications) ? VBA is a powerful programming language built into Microsoft Office applications like PowerPoint that allows you to create macros, functions, and scripts to automate repetitive tasks, manipulate objects, and customize the behavior of your presentations .

In this comprehensive guide, we’ll cover everything you need to know about VBA PowerPoint design , from the basics of the VBA language to advanced techniques for creating dynamic and interactive presentations.

What is VBA in PowerPoint?

VBA (Visual Basic for Applications) is an event-driven programming language from Microsoft that is built into most Office applications, including PowerPoint. It enables you to write macros and scripts to automate tasks and add custom functionality to your PowerPoint presentations.

Some key things to know about VBA in PowerPoint:

  • VBA is a subset of the Visual Basic programming language adapted for Office applications
  • You access the VBA editor in PowerPoint via the Developer tab
  • VBA macros and scripts are stored within a PowerPoint presentation in modules
  • VBA can interact with PowerPoint objects and their properties and methods
  • You can attach macros to buttons, shapes and other triggers in a presentation

Learning VBA allows you to become a PowerPoint power user and automate nearly any aspect of presentation design .

Getting Started with VBA in PowerPoint

To get started with VBA programming in PowerPoint, you first need to enable the Developer tab in the PowerPoint ribbon if it’s not already visible.

  • Go to File > Options > Customize Ribbon
  • Check the box next to “Developer” under Main Tabs

You should now see the Developer tab appear in the PowerPoint ribbon interface.

Next, open the Visual Basic Editor:

  • Go to the Developer tab
  • Click the “Visual Basic” button in the Code group

This will open the VB Editor, where you can view and edit the VBA code behind your presentation.

Some other key things to know as you get started:

  • You write VBA code in the code window within a module
  • To insert a new module, go to Insert > Module in the VB Editor
  • To run a macro, you can click the “Run Sub/UserForm” button (green play icon)
  • Use the Object Browser (F2) to explore PowerPoint’s object model
  • Find help and examples in the Microsoft documentation and VBA developer community

PowerPoint’s Object Model

To automate PowerPoint with VBA , you need to understand the PowerPoint object model – the hierarchy of objects that make up a presentation and their properties and methods that you can manipulate with code.

Here is an overview of some of the key objects in PowerPoint’s object model:

Each object has various properties (attributes) and methods (actions) associated with it. For example:

  • Presentation.Slides.Count returns the number of slides in a presentation
  • Slide.Copy method copies a slide to the clipboard
  • Shapes.AddTextbox method creates a new text box shape

By calling these properties and methods in your VBA code, you can automate and manipulate virtually any part of a presentation.

Creating Macros to Automate PowerPoint

The most common way to automate PowerPoint with VBA is by creating macros – snippets of code that perform a specific task which you can run whenever needed.

Here’s an example of a simple macro that inserts a new slide:

To create a macro:

  • Open the VB Editor (Developer tab > Visual Basic)
  • Insert a new module (Insert > Module)
  • Type (or paste) the macro code into the code window
  • To run the macro, click the “Run Sub/UserForm” button or press F5

You can also attach a macro to a button or shape so that it runs when clicked:

  • Insert a shape or button on your slide
  • Right-click it and select “Assign Macro”
  • Choose the macro to attach and click OK

Some other examples of useful PowerPoint VBA macros:

  • Applying a custom theme/template to a presentation
  • Looping through slides and applying formatting
  • Exporting slides to images or PDF
  • Generating a table of contents or agenda slide
  • Integrating data from Excel to create charts

The possibilities are endless – if you find yourself performing a repetitive PowerPoint task, chances are you can speed it up with a VBA macro.

Customizing the PowerPoint UI with VBA

In addition to automating slide design tasks, you can use VBA to customize the PowerPoint user interface itself. This includes:

  • Adding custom ribbon tabs and buttons
  • Creating custom task panes
  • Modifying built-in menus and dialog boxes
  • Showing custom forms and input boxes

For example, here’s how you can add a custom button to the PowerPoint ribbon:

  • Open the VB Editor (Developer > Visual Basic)
  • Right-click your presentation in the Project window, select Insert > Module
  • Paste in the following code:
  • Save and close the workbook
  • Create a folder on your computer called “RibbonXML”
  • In that folder, create a text file called “customUI14.xml”
  • Open the XML file and paste this code:
  • Save and close the XML file
  • Open your PowerPoint presentation, and you should see the new custom button!

This just scratches the surface of how you can use VBA to customize the PowerPoint interface to fit your workflows. By leveraging the power of VBA and the Office Fluent UI (RibbonX), you can build your own custom functionality right into PowerPoint.

Advanced VBA PowerPoint Techniques

Once you’ve mastered the basics of VBA PowerPoint automation , there are many advanced techniques you can explore to take your presentations to the next level:

  • Working with external data : You can use VBA to pull data from external sources like Excel spreadsheets, Access databases, or web APIs and integrate it into your slides.
  • Creating interactive elements : Use VBA to create navigation buttons, pop-up dialog boxes, rollover effects and other interactive elements to make your presentations more engaging.
  • Generating presentations dynamically : You can write VBA scripts that generate entire PowerPoint decks dynamically based on data and templates.
  • Add-ins and plugins : Package your VBA PowerPoint automations into add-ins and plugins that you can share and deploy across your organization.

There are also many helpful references, code libraries and frameworks in the VBA community that can accelerate your PowerPoint automation projects:

  • Microsoft VBA PowerPoint reference
  • VSTO (Visual Studio Tools f o r Office)
  • PowerPoint VBA code examples and snippets on GitHub

By leveraging these resources and continually honing your VBA programming skills, you can become a master of PowerPoint automation and design.

Final Thoughts

VBA is an incredibly powerful tool for automating PowerPoint design tasks and workflows . By learning the basics of the VBA programming language and PowerPoint’s object model, you can create macros and scripts to automate virtually any aspect of presentation creation – from slide formatting and layout to data integration and user interaction.

As you advance your VBA PowerPoint skills , you’ll be able to create more sophisticated automations, customizations and add-ins that can save countless hours of repetitive work and enable you to design better presentations faster.

How do I access the VBA editor in PowerPoint?

To access the VBA editor in PowerPoint, first enable the Developer tab in the PowerPoint ribbon (File > Options > Customize Ribbon). Then, click the “Visual Basic” button in the Code group on the Developer tab.

What is the PowerPoint object model?

The PowerPoint object model is the hierarchy of objects that make up a presentation, such as Application , Presentation , Slide , SlideRange , Shapes , and Selection . Each object has various properties and methods that you can manipulate with VBA code to automate and customize your presentations.

How do I create a macro in PowerPoint?

To create a macro in PowerPoint, open the VB Editor (Developer tab > Visual Basic), insert a new module (Insert > Module), and type or paste your macro code into the code window. To run the macro, click the “Run Sub/UserForm” button or press F5.

Can I customize the PowerPoint user interface with VBA?

Yes, you can use VBA to customize the PowerPoint user interface, including adding custom ribbon tabs and buttons, creating custom task panes, modifying built-in menus and dialog boxes, and showing custom forms and input boxes.

What are some advanced VBA PowerPoint techniques?

Some advanced VBA PowerPoint techniques include working with external data sources, creating interactive elements, generating presentations dynamically based on data and templates, and packaging your automations into add-ins and plugins that you can share and deploy across your organization.

  • Recent Posts

Trish Dixon

  • How to Embed a Google Map in PowerPoint Slides: Easy Guide – December 3, 2024
  • How to Create a Photo Slideshow in PowerPoint: Easy Guide – November 27, 2024
  • How to Embed Spotify Song in PowerPoint? (2 Easy Methods) – November 21, 2024

Leave a Reply Cancel reply

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

Save my name, email, and website in this browser for the next time I comment.

Latest Posts

How to embed a google map in powerpoint slides: easy guide.

Learn how to embed interactive Google Maps in PowerPoint slides with this simple guide. Enhance your presentations with dynamic maps using two easy methods.

How to Create a Photo Slideshow in PowerPoint: Easy Guide

Learn how to create a photo slideshow in PowerPoint with easy steps, including adding transitions, animations, and music for professional results.

How to Embed Spotify Song in PowerPoint? (2 Easy Methods)

Learn how to embed Spotify songs in PowerPoint. Use hyperlinks or downloaded audio files to add music for a professional and engaging presentation.

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Presentation object (PowerPoint)

  • 11 contributors

Represents a Microsoft PowerPoint presentation.

The Presentation object is a member of the Presentations collection. The Presentations collection contains all the Presentation objects that represent open presentations in PowerPoint.

The following examples describe how to:

Return a presentation that you specify by name or index number

Return the presentation in the active window

Return the presentation in any document window or slide show window you specify

Use Presentations ( index ), where index is the presentation's name or index number, to return a single Presentation object. The name of the presentation is the file name, with or without the file name extension, and without the path. The following example adds a slide to the beginning of Sample Presentation.

Note that if multiple presentations with the same name are open, the first presentation in the collection with the specified name is returned.

Use the ActivePresentation property to return the presentation in the active window. The following example saves the active presentation.

Use the Presentation property to return the presentation that's in the specified document window or slide show window. The following example displays the name of the slide show running in slide show window one.

PowerPoint Object Model Reference

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

Was this page helpful?

Additional resources

VBA Resources

  • Career Guides
  • Interview Prep Guides
  • Free Practice Tests
  • Excel Cheatsheets

🕛 Time: 10:00-11:00 am EST 📅 Date: 12th December 💻 Venue: Online 🏃‍♂️ Seats : Limited

Girl_Image

VBA PowerPoint

Publication Date :

02 Jul, 2019

Blog Author :

Edited by :

Ashish Kumar Srivastav

Reviewed by :

Dheeraj Vaidya, CFA, FRM

Table Of Contents

Excel VBA PowerPoint

Using VBA, we can automate the work we do for PowerPoint. But first, to use VBA code or snippets to work in PowerPoint, first work through the security options in PowerPoint to enable all Macros. Then, we can use PowerPoint VBA reference for Macros in MS PowerPoint.

The beauty of VBA is that we can reference other Microsoft products like "Microsoft Word" and "Microsoft PowerPoint." We usually create reports in Excel and then create PowerPoint presentations. All Excel users usually spend a considerable amount of time preparing the presentation from Excel data and reports. If you spend considerable time preparing PowerPoint presentations, this tutorial will show you how to create a PowerPoint presentation from Excel using VBA Coding .

Table of contents

Enable powerpoint object model, vba tutorial to create powerpoint presentation, recommended articles.

VBA PowerPoint

Let us follow the below steps..

VBA Powerpoint Step 1

We can create PPT in "Early Binding" and "Late Binding." Finally, we will show you how to create a PowerPoint presentation using the “Early Binding” technique .

Usually, from Excel, we prepare presentations based on charts and interpretation of the charts. So, for this purpose, we have created some simple excel charts and interpretations in the same worksheet.

VBA Powerpoint Step 3.1

Step 1: Start the subroutine in VBA . We have already enabled the PowerPoint object model in the earlier steps to access PowerPoint. To access this, we need to declare the variable as PowerPoint.Application.

VBA Powerpoint Step 4

Step 2: To add the presentation to PowerPoint, we need to declare a variable as PowerPoint.Presentation.

VBA Powerpoint Step 5

Step 3: After adding the presentation to the PowerPoint, we need to add a Slide to declare the variable as PowerPoint.Slide.

VBA Powerpoint Step 6

Step 4: Once we add the slide to the PowerPoint, we need to use shapes in the PowerPoint, i.e., text boxes, to declare a variable as PowerPoint.Shape.

VBA Powerpoint Step 7

Step 5: Now, we need to declare the variable as Excel to access all the charts in the worksheet.ChartObjects.

VBA Powerpoint Step 8

These variables are enough to start the proceedings.

Step 6: Now, we need to launch the PowerPoint from Excel. Since it is an external object, we need to set this as a new PowerPoint.

Pp Step 9

It will launch the new PowerPoint from Excel.

Step 7: The variable PPApp is equal to the PowerPoint we launched. Now, make this PowerPoint visible and maximize the window.

 Code:

PP Step 10

Now, just run the code using the F5 key or manually. You should see the PowerPoint app launched like the one below.

Pp Step 10.1

Step 8: We need to add a presentation to the PowerPoint app we have launched.

Pp Step 11

Now, we should see the PowerPoint presentation like this.

PP Step 11.1

Step 9: We need to add a slide after adding the presentation

Pp Step 12

Now, this will add the title slide like the below.

PP Step 12.1

Step 10:   Now that we have more than one chart in the worksheet, we need to loop through each chart and paste it into the presentation. Below is the code to copy and paste the chart and interpretation.

Below is the complete code for you.

This article is a guide to VBA PowerPoint Tutorial. Here, we learn how to create a PowerPoint presentation using the "Early Binding" technique in VBA code, examples, and a downloadable template. Below are some useful Excel articles related to VBA: -

  • VBA ByRef Function
  • Excel VBA Charts
  • VBA Val Function
  • Create VBA Pivot Table

Youtube

Recables Profile Logo

Power Up Your Presentations: A Guide to Using VBA in PowerPoint

In this comprehensive guide, we’ll explore how to use the power of VBA (Visual Basic for Applications) within PowerPoint, boosting your productivity by automating tasks and creating dynamic presentations.

Why Use VBA in PowerPoint?

While PowerPoint offers a range of built-in features, VBA unlocks a new level of customization and automation. You can update multiple slides with a single click, create interactive elements, or dynamically link data from an Excel spreadsheet. VBA makes all these a reality.

How to Get Started with VBA in PowerPoint

1. save as macro-enabled presentation.

The first thing that you need to do is to save your presentation file as a PowerPoint Macro-Enabled Presentation (*.pptm) . This allows your presentation file to contain VBA code. To do this:

  • Go to File > Save As and choose a location to save your file.
  • In the Save as type dropdown menu, select PowerPoint Macro-Enabled Presentation (*.pptm) . [3]

Saving in the .pptm format signals to PowerPoint that the file contains macros (VBA code) and should be treated accordingly. Standard .pptx files cannot store VBA code. [3]

2. Activate the Developer Tab

The Developer tab is how you add VBA code in PowerPoint. It is not displayed by default. Here’s how to activate it:

Enable Developer Tab PowerPoint

  • Navigate to File > Options > Customize Ribbon .
  • On the right-hand side, locate the Developer checkbox and ensure it’s ticked.
  • Confirm by clicking OK . The Developer tab will now appear in the PowerPoint ribbon.

The Developer tab is where you can find the essential VBA tools including the Visual Basic editor for writing code, macro management options, and controls for creating interactive elements.

3. Uncover Object Names

Before writing your VBA code, you need to know the precise names of the objects you want to manipulate. PowerPoint assigns unique names to each element within a slide. Here’s how to find them:

Get PowerPoint Slide Element Names

  • Select the object you want to work with (e.g., a title textbox, a shape, or an image).
  • When the Shape Format tab appears in the ribbon, click on Selection Pane .
  • A panel will open on the right, listing all objects on the current slide with their corresponding names.

VBA relies on accurate object names to interact with specific elements. By using the exact name of the elements that you want to manipulate, you can ensure that your code works properly. Incorrect names will lead to errors in your code and relying on general names is also a common reason for code breaking down.

Writing Your First VBA Code

Now let’s dive into writing a simple PowerPoint VBA macro to showcase some possibilities. In this example, we will automatically change the title and subtitle text on the first slide of the presentation.

4. Insert a VBA Module

Modules serve as containers for your VBA code within the PowerPoint project. This helps keep your code organized:

Insert new VBA module in PowerPoint

  • Go to the Developer tab and click Visual Basic .
  • In the Visual Basic editor, click Insert > Module .

5. Crafting the Code

Within the newly created module, type the following code:

Let’s break down the code to see what each line does:

  • Sub TitleSubtitleChange() : This line defines the start of a procedure named “TitleSubtitleChange.” Procedures are blocks of code that perform specific tasks.
  • With ActivePresentation.Slides(1) : This line indicates we are working with the active presentation and specifically its first slide.
  • .Shapes(“Title 1”).TextFrame.TextRange.Text = “I changed the title” : This line targets the shape named “Title 1” on the first slide, accesses its text frame, and changes the text content to “I changed the title.”
  • .Shapes(“Subtitle 2”).TextFrame.TextRange.Text = “This is the change” : This line performs a similar action, changing the text of the shape named “Subtitle 2” to “This is the change.”
  • End With : This line ends the “With” block.
  • End Sub : This line signifies the end of the procedure.

VBA Best Practices

Writing clean, efficient, and understandable code is crucial, especially when collaborating with others or revisiting your work in the future. Here are some best practices:

  • Meaningful Naming : Use descriptive names for your procedures, variables, and constants. A name like “UpdateSlideTitles” is much more informative than “Sub1.”
  • Comments : Explain complex logic or the purpose of specific code sections using comments. Comments start with an apostrophe (‘).
  • Indentation : Properly indent your code to visually represent the code’s structure and hierarchy, making it easier to read.
  • Modularization : Break down large tasks into smaller, manageable procedures. This improves reusability and makes debugging simpler.
  • Testing : Thoroughly test your code with various scenarios to ensure it behaves as intended.

6. Running Your VBA Code

You’ve written the code, now it’s time to see it in action:

  • Save your code within the Visual Basic editor.
  • Click the green “Run” button (or press F5) to execute your code.
  • Switch back to your PowerPoint presentation to witness the title and subtitle on the first slide change automatically.

Beyond the Basics: Exploring VBA’s Potential

If you learn better by watching, here’s a video that explains the steps. Follow along and you’ll have a better idea of where to click and what to type:

This is just a glimpse of what you can do with VBA in PowerPoint. Here are some other things that you could explore doing:

  • Link Excel data to PowerPoint to create dynamic charts and tables that update automatically.
  • Build interactive quizzes or feedback forms within your presentations.
  • Automate repetitive formatting tasks, such as applying a specific design to all slides.

VBA is a relatively easy skill to master and by doing so, you can transform your PowerPoint presentations as well as your presentation creation process.

Benjamin Wallace

' src=

A software engineer, I have a strong interest in technology, bot software and hardware. Blogging is a way to share what I have learned and hopefully people will find it useful.

Similar Posts

How to Extract Quotes From a Text File Using VBA in Excel

How to Extract Quotes From a Text File Using VBA in Excel

Learn how to easily extract quotes from text files using VBA in Excel. Step-by-step guide with sample code makes text analysis simple.

VBA PowerPoint To Delete Slide Notes

VBA PowerPoint To Delete Slide Notes

In this post, let’s look at how we can use VBA in PowerPoint to delete all the slide notes in your presentation file. This can be very useful if you want to delete all the notes in a presentation before you send it out to your audience. You don’t need this if you only have…

VBA Test If Date Parameter is Null

Testing for Null Date Parameters in VBA

Working with dates is always tricky and VBA is no exception. One particularly common problem is missing dates or null dates. In this post, we will explore how to reliably test for null date parameters in your VBA code, ensuring that it is robust and help to prevent unexpected errors. What are Null Dates? A…

Leave a Reply Cancel reply

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

Username or Email Address

Remember Me Forgot Password?

First name *

Last name *

Mobile Number *

Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our privacy policy .

Get New Password

PowerUP with POWERPOINT

3. Getting Started with VBA

powerupwithpowerpoint

  • December 3, 2023
  • PowerPoint VBA

In previous blog you learned some basic of VBA. This Blog will explain how to access the VBA Editor, how to write simple scripts in VBA, how to attach those scripts to buttons and objects, and how to protect your scripts with a password. When you complete reading this blog, you will know the basics of writing a script and using it in a PowerPoint presentation, and you will be all ready to do some interesting things with VBA.

  • Accessing the VBA Editor

Once you start a PowerPoint project, you get into VBA by holding down the ALT key and hitting the F11 key (Option-F11 on a MacOS). Alternatively, go to the Developer tab of the Ribbon and click on Visual Basic. If you don’t have the Developer tab, go back to blog#1 to review how to get it.

vba powerpoint presentations

At this point, you should see two small windows on the left (the Project window and the Properties window) and a large blank area on the right of the screen.  

vba powerpoint presentations

You also might not see either the Project window or the Properties window; you can get them back by choosing them from the View menu.

vba powerpoint presentations

Choose Module from the Insert menu , and you will get a window in the blank area. The window probably will be named “Module1”. This is where you will write your VBA procedures.

vba powerpoint presentations

While we are here, let’s write one VBA code. Type the following:

Note that the computer will type the End Sub and the parentheses for you if you just hit Return or Enter on your keyboard after typing “ Sub SayHello ” .

vba powerpoint presentations

Now go to the Run menu , and select Run Sub/UserForm . You should get a message box that says Hello World!

vba powerpoint presentations

Congratulations! You have just written and executed your first VBA procedure successfully. Click the OK button, and you can do some more.

  • What If It Didn’t Work?

When you type code, it doesn’t always work the first time (or the second time or the third time or . . .), i will give lots of great ideas in my upcoming blogs for fixing what’s wrong with your code; but for now here’s a quick tip. After typing some code, make sure that it starts with Sub and ends with End Sub . The next most common mistakes are: putting a space between Say and Hello on the first line (it should be one word) and getting the quotes wrong around Hello World! (they’re regular, ordinary double quotes, and when you have an open quote, you need a close quote). Check everything carefully, and you’ll be able to get this to work.

  • Be a Scripter: Change Things in Quotes

If your goal is to be a programmer, you should try to understand every detail in every line of code. If your goal is to be a scripter, you should have a basic understanding of what the code does, and you should try to understand as much of the details as you can. But the most important thing you can understand as a scripter is what you can change. One clue is that you can change most things that are in quotes. In this code, the word Hello World! is in quotes, and “ Hello World! ” popped up on the screen when you ran the procedure. If you want something else to pop up on the screen (like “ Hello, PowerPoint! ” or “ My First VBA code ” or “ My Name is, Bla bla ”) then put that in the quotes in your code instead. Give it a Try..!!

  • Subroutine, Procedure, or Macro

What do we call the code that you just wrote (the stuff that starts with Sub and ends with End Sub )? The word Sub is short for subroutine . It is commonly referred to as a procedure , and these terms will be used in all of my upcoming blog posts. It could also be referred to as a macro , and you will see that term in the Developer tab of the Ribbon (refer image below). In short, any of those terms is correct and are equivalent.

vba powerpoint presentations

  • Attach Your VBA Script to a PowerPoint Button

Now that you have a Macro written, you may want to access it from within PowerPoint. You can do this by assigning/attaching this Macro to a button (or any drawing shape that you want).

Assuming that you are still at VBA editor, you can click on old style PowerPoint icon on top left corner to Return back to Microsoft PowerPoint (refer image below) .

Note: You can also close the Visual Basic Editor by clicking on the X in the upper right-hand corner of the screen. Don’t worry about losing your VBA scripts when you close the editor. Your VBA scripts are part of your PowerPoint presentation. When you save your presentation, your scripts will be saved with it. When you return to the editor, your scripts will still be there.

vba powerpoint presentations

Now to Attach Your VBA Script to a PowerPoint Button, you must first add an action button to your slide. You will find action buttons under shapes menu, at the bottom most section.

vba powerpoint presentations

You can pick any one of the action buttons and draw it on the slide. As soon as you finish drawing the button, by dragging the mouse to form the button or just clicking where you want the button to appear on the slide, you will be presented with the Actions Settings dialogue box . Choose Run Macro , and select SayHello (the name of the procedure you just wrote) as the macro to run. Click OK .

vba powerpoint presentations

Buttons are only active in Slide Show View, so go to Slide Show View by pressing F5 key on your keyboard ( Note : If you have more than one slide, then press ‘ Shift+F5 ’ keys to start slide show from current slide). Now, click on your action button, and you should get the same “ Hello World! ”  message you got earlier when running your Macro.

vba powerpoint presentations

Now go back to Normal View (also known as Edit View) by hitting the Escape key on your keyboard. To finish your button, right-click on it and choose Edit Text from the fly-out menu or select the button and just start typing. You can now add text to describe what your button does. This text will show up on the button, so users will know what they are clicking when they click your button. For this button, you might type “ Say Hello ”.

  • Attach Your VBA Script to any Object/Shape

Not just to a button, you can assign your VBA script to any object you want. Use the drawing tools to draw a shape (Choose Shapes menu from the Insert tab of the Ribbon),  Once you have drawn the shape, click on it to select it. Now choose Action from the Insert tab of the Ribbon, you will get the same dialogue box as in case of action button, you can choose Run Macro and the SayHello macro, exactly as you did earlier. Now you can click on the drawn object just like you can click on the button.

vba powerpoint presentations

This method works for any PowerPoint object, not just the ones you draw yourself. You can insert clip arts, pictures from other sources, and even make text in your slide clickable by highlighting the text and following the same steps.

  • Securing Your VBA Script

In many circumstances, you may not want others to see your VBA Script (Example: You have written VBA script for a Quiz game and you don’t want to reveal their answers) and It is very easy to protect your VBA code with a password. Return back to VBA Editor where you edit the VBA code, select VBAProject Properties from the Tools menu and click on the Protection tab. Check the box that is labeled Lock project for viewing , type a password in the “Password” box, and type the same password in the “ Confirm password ” box and then click Ok .

vba powerpoint presentations

Now, whenever you want to view or edit the VBA code, you will be asked to type this password. Don’t forget it, else even you will not be able to access your own project.!!

Leave a Reply Cancel Reply

You must be logged in to post a comment.

Trending now

COMMENTS

  1. Presentations object (PowerPoint)

    In this article. A collection of all the Presentation objects in Microsoft PowerPoint. Each Presentation object represents a presentation that's currently open in PowerPoint.. Remarks. The Presentations collection doesn't include open add-ins, which are a special kind of hidden presentation. You can, however, return a single open add-in if you know its file name.

  2. PowerPoint VBA Macro Examples & Tutorial

    Saves the presentation as a PDF; PowerPoint Application. When VBA code is running within a PowerPoint Presentation, PowerPoint Application is the default application and it can be manipulated without explicitly reference. Create a New Presentation. To create a presentation, use the Add method of PowerPoint application.

  3. How to use VBA in PowerPoint: A beginner's guide

    Presentation technology / Industry insights; Comments: 2; You can do some really cool things in Microsoft Office with just a few lines of Visual Basic for Applications (VBA) - from creating your own custom formula in Excel to correcting branded content in PowerPoint to merging address data for a mail campaign in Word.

  4. VBA PowerPoint Design: Automate Presentations with Macros

    Advanced VBA PowerPoint Techniques. Once you've mastered the basics of VBA PowerPoint automation, there are many advanced techniques you can explore to take your presentations to the next level:. Working with external data: You can use VBA to pull data from external sources like Excel spreadsheets, Access databases, or web APIs and integrate it into your slides.

  5. PowerPoint Visual Basic for Applications (VBA) reference

    Object model reference: Provides reference materials for the PowerPoint object model. See also. PowerPoint (Office client development) Support and feedback. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

  6. VBA PowerPoint

    See some interesting examples of how to create a PowerPoint presentation using Excel VBA. Example #1. Suppose you want to create a Title page for your PowerPoint presentation via code. You can do that by using VBA PowerPoint online. Step 1: Define the subroutine, which will create a PowerPoint Title page.

  7. Presentation object (PowerPoint)

    The Presentation object is a member of the Presentations collection. The Presentations collection contains all the Presentation objects that represent open presentations in PowerPoint. The following examples describe how to: Return a presentation that you specify by name or index number. Return the presentation in the active window

  8. VBA Tutorial to Create Powerpoint Presentation

    But first, to use VBA code or snippets to work in PowerPoint, first work through the security options in PowerPoint to enable all Macros. Then, we can use PowerPoint VBA reference for Macros in MS PowerPoint. The beauty of VBA is that we can reference other Microsoft products like "Microsoft Word" and "Microsoft PowerPoint."

  9. Power Up Your Presentations: A Guide to Using VBA in PowerPoint

    The first thing that you need to do is to save your presentation file as a PowerPoint Macro-Enabled Presentation (*.pptm). This allows your presentation file to contain VBA code. To do this: Go to File > Save As and choose a location to save your file. In the Save as type dropdown menu, select PowerPoint Macro-Enabled Presentation (*.pptm). [3]

  10. 3. Getting Started with VBA

    Your VBA scripts are part of your PowerPoint presentation. When you save your presentation, your scripts will be saved with it. When you return to the editor, your scripts will still be there. Now to Attach Your VBA Script to a PowerPoint Button, you must first add an action button to your slide. You will find action buttons under shapes menu ...