Loop Through Each Slide In Your Active PowerPoint Presentation
What This VBA Code Does
Often times we want to make changes that affect every slide in the PowerPoint presentation. The best way to do this is to use a loop that can apply the same change to every single slide in the presentation. Below shows how you can accomplish this by adding a transition effect to every PowerPoint slide.
Using VBA Code Found On The Internet
Now that you’ve found some VBA code that could potentially solve your Excel automation problem, what do you do with it? If you don’t necessarily want to learn how to code VBA and are just looking for the fastest way to implement this code into your spreadsheet, I wrote an article (with video) that explains how to get the VBA code you’ve found running on your spreadsheet.
Getting Started Automating Excel
Are you new to VBA and not sure where to begin? Check out my quickstart guide to learning VBA . This article won’t overwhelm you with fancy coding jargon, as it provides you with a simplistic and straightforward approach to the basic things I wish I knew when trying to teach myself how to automate tasks in Excel with VBA Macros.
Also, if you haven’t checked out Excel’s latest automation feature called Power Query , I have put together a beginner’s guide for automating with Excel’s Power Query feature as well! This little-known built-in Excel feature allows you to merge and clean data automatically with little to no coding!
How Do I Modify This To Fit My Specific Needs?
Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to get quick answers to complex problems in Excel, PowerPoint, VBA, you name it !
I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee that 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).
I wish you the best of luck and I hope this tutorial gets you heading in the right direction!
After 10+ years of creating macros and developing add-ins, I've compiled all the hacks I wish I had known years ago!
Keep Learning
Find And Replace All With VBA In PowerPoint
What This VBA Code Does This post is a follow-up article to Find And Replace With Excel VBA. The following...
Loop Through All Chart Sheets In An Excel Workbook
What This VBA Code Does There are two types of Sheets within an Excel Workbook. Worksheets Chart Sheets The below...
Remove Page Breaks From All Open Spreadsheets
What This VBA Code Does Ever get those annoying dotted lines on all your spreadsheets after viewing a print preview?...
Chris Newman
Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.
- Search forums
- Board Rules
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
- If you would like to post, please check out the MrExcel Message Board FAQ and register here . If you forgot your password, you can reset your password .
- Question Forums
- Excel Questions
looping through all shapes in all slides in a powerpoint presentation
- Thread starter Thread starter LAWS
- Start date Start date Jan 4, 2020
- Jan 4, 2020
i want to loop through all slides and 1) check if a textbox existss, if not move o the next slide 2) if there is a textbox, copy the text to my excell sheet kindly assist i have the following code: VBA Code: Sub loop_through_powerpoint_textboxes() 'Declare varriables Dim ppapp As New PowerPoint.Application Dim ppslide As PowerPoint.Slide Dim pppres As PowerPoint.Presentation Dim ppobj As PowerPoint.Shape Dim n As Long With ppapp .WindowState = ppWindowMaximized .Visible = msoCTrue .Activate End With Set pppres = ppapp.Presentations.Open("C:\Users\Teacher-F894D1\Documents\CBC DECEMBER 2019 TRAINING\3. AUTHENTIC ASSESSMENT.pptx") 'Set ppslide = ActivePresentation.Slides n = pppres.Slides.Count For i = 1 To n Set ppslide = pppres.Slides(i) If ppobj.Type = msoTextBox Then ppobj.TextFrame.TextRange.Copy Sheet1.Activate ActiveCell.PasteSpecial xlPasteAll ActiveCell.Offset(1, 0).Select End If Next i End Sub thanks
Excel Facts
Similar threads.
- Question Question
- Oct 2, 2023
- Jun 12, 2023
- Dec 11, 2022
- Jul 27, 2022
- Jun 7, 2022
Forum statistics
Share this page.
We've detected that you are using an adblocker.
Which adblocker are you using.
Disable AdBlock
Disable AdBlock Plus
Disable uBlock Origin
Disable uBlock
Powerpoint VBA Reference Library
The code below is intended to be a basic reference to anybody trying to use VBA code for Powerpoint. It’s certainly not complete, but it is code I’ve used for various reasons. I will try to add to and improve this reference as I use more PowerPoint VBA code.
Referencing presentations, slides and shapes
Count the number of slides, get the slide index number of the current slide.
ppLayoutBlank is just one of a number of available layout options.
Delete Slides
move slides, looping through all the slides of the active presentation, looping through all the shapes on the active slide, looping through all shapes on all slides, looping through all linked shapes on all slides.
If you are applying a method, the other option is to apply the method to all shapes, even if they are not linked. You will need to handle the errors where that shape is not a linked shape.
Managing Links
Some of the methods related to links occur at the presentation level, whilst others occur at the shape level.
Presentation level methods
Shape level methods.
The code snippets in this section do not stand alone. They must be used where the pptShape has been set or defined through a loop.
Discover how you can automate your work with our Excel courses and tools.
Excel Academy The complete program for saving time by automating Excel.
Excel Automation Secrets Discover the 7-step framework for automating Excel.
Office Scripts: Automate Excel Everywhere Start using Office Scripts and Power Automate to automate Excel in new ways.
2 thoughts on “Powerpoint VBA Reference Library”
Hi, I found this nice page on PowerPoint snippets, but could not find the VBA code to get a reference to an existing instance of PPT. It’s called CreateOrGetObject or GetOrCreateObject or something like that. If you ever update this page, that would be a useful snippet to include. I bookmarked this page in case I need some of these snippets one day. Thank you!
Thanks Kevin, that’s good feedback. I’ll add that in the next time I update it 🙂
Leave a Comment Cancel reply
PowerPoint Top Contributor: John Korchok ✅
November 12, 2024
PowerPoint Top Contributor:
John Korchok ✅
- Search the community and support articles
- Microsoft 365 and Office
- Search Community member
Ask a new question
VBA reusable loops function
I am using several times for each and for loop in powerpoint vba, to loop all the slides and shapes. for example,
For i = Activepresentation.slides(i).count
For i = 1 To ActiveWindow.Selection.ShapeRange.Count
Dim sld as slide
Dim shp as shape
For Each sld In ActivePresentation.Slides
For Each shp in sld.shapes
Is there a way to create a reusable function for these loops? so that, it can be called, whenever required.
Thanks for your great help.
Thanks and Regards,
Report abuse
Reported content has been submitted
- Volunteer Moderator
There's probably some obscure way of doing this that would allow you to pass the name of another subroutine to the function so that it knows what to do.
It'd be simpler, though, to maintain a file of commonly used code that you could easily insert into your projects. There's a VB/VBA add-in called MZ-Tools that lets you create a library of code snippets, among loads of other extremely useful features. It used to be free but now costs $65 or so.
It's worth having a look:
https://www.mztools.com/index.aspx
I have no financial interest in this product; I've used for several years and find it indispensible, if only for the couple of features I use regularly (the ability to insert customized error handlers alone is worth the price)
Was this reply helpful? Yes No
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
Thanks for your feedback.
I would not use
If shp.type=msoChart
It will fail if the chart is in a placeholder
You could maybe try something like
Sub deleteLegend()
Call fixChart(1)
Sub DeleteChart()
Call fixChart(2)
Sub fixChart(action As Long)
' Declare your variables!
Dim sld As Slide
Dim shp As Shape
For Each shp In sld.Shapes
If shp.HasChart Then
Select Case action
shp.Chart.HasLegend = False
1 person found this reply helpful
Replies (11)
Question info.
- Norsk Bokmål
- Ελληνικά
- Русский
- עברית
- العربية
- ไทย
- 한국어
- 中文(简体)
- 中文(繁體)
- 日本語
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
- 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.
SlideRange object (PowerPoint)
- 7 contributors
A collection that represents a notes page or a slide range, which is a set of slides that can contain as little as a single slide or as much as all the slides in a presentation.
You can include whichever slides you want — chosen from all the slides in the presentation or from all the slides in the selection — to construct a slide range. For example, you could construct a SlideRange collection that contains the first three slides in a presentation, all the selected slides in the presentation, or all the title slides in the presentation.
Just as you can work with several slides at the same time in the user interface by selecting them and applying a command, you can work with several slides at the same time programmatically by constructing a SlideRange collection and applying properties or methods to it. And just as some commands in the user interface that work on single slides aren't valid when multiple slides are selected, some properties and methods that work on a Slide object or on a SlideRange collection that contains only one slide will fail if they're applied to a SlideRange collection that contains more than one slide. In general, if you can't do something manually when more than one slide is selected (such as return the individual shapes on one of the slides), you can't do it programmatically by using a SlideRange collection that contains more than one slide.
For those operations that work in the user interface whether you have a single slide or multiple slides selected (such as copying the selection to the Clipboard or setting the slide background fill), the associated properties and methods will work on a SlideRange collection that contains more than one slide. Here are some general guidelines for how these properties and methods behave when they're applied to multiple slides.
Applying a method to a SlideRange collection is equivalent to applying the method to all the Slide objects in that range as a group.
Setting the value of a property of the SlideRange collection is equivalent to setting the value of the property in each slide in that range individually (for a property that takes an enumerated type, setting the value to the "Mixed" value has no effect).
A property of the SlideRange collection that returns an enumerated type returns the value of the property for an individual slide in the collection if all slides in the collection have the same value for that property. If the slides in the collection don't all have the same value for the property, the property returns the "Mixed" value.
A property of the SlideRange collection that returns a simple data type (such as Long , Single , or String ) returns the value of the property for an individual slide in the collection if all slides in the collection have the same value for that property. If the slides in the collection don't all have the same value for the property, the property will return - 2 or generate an error. For example, using the Name property on a SlideRange object that contains multiple slides will generate an error because each slide has a different value for its Name property.
Some formatting properties of slides aren't set by properties and methods that apply directly to the SlideRange collection, but by properties and methods that apply to an object contained in the SlideRange collection, such as the ColorScheme object. If the contained object represents operations that can be performed on multiple objects in the user interface, you'll be able to return the object from a SlideRange collection that contains more than one slide, and its properties and methods will follow the preceding rules. For example, you can use the ColorScheme property to return the ColorScheme object that represents the color schemes used on all the slides in the specified SlideRange collection. Setting properties for this ColorScheme object will also set these properties for the ColorScheme objects on all the individual slides in the SlideRange collection.
The following examples describe how to:
Return a set of slides that you specify by name or index number
Return all or some of the selected slides in a presentation
Return a notes page
Apply properties and methods to a slide range
Use Slides.Range ( index ), where index is the name or index number of the slide or an array that contains either names or index numbers of slides, to return a SlideRange collection that represents a set of slides in a presentation. Use the Array function to construct an array of names or index numbers. The following example sets the background fill for slides one and three in the active presentation.
The following example sets the background fill for the slides named "Intro" and "Big Chart" in the active presentation. Note that slides are assigned automatically generated names of the form Sliden (where n is an integer) when they're created. To assign a more meaningful name to a slide, use the Name property.
Although you can use the Range method to return any number of slides, it is simpler to use the Item method if you only want to return a single member of the SlideRange collection. For example, Slides(1) is simpler than Slides.Range(1) .
Use the SlideRange property of the Selection object to return all the slides in the selection. The following example sets the background fill for all the selected slides in window one, assuming that there's at least one slide selected.
Use Selection.SlideRange ( index ), where index is the slide name or index number, to return a single slide from the selection. The following example sets the background fill for slide two in the collection of selected slides in window one, assuming that there are at least two slides selected.
Use the NotesPage property to return a SlideRange collection that represents the specified notes page. The following example inserts text into placeholder two (the notes area) on the notes page for slide one in the active presentation.
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?
IMAGES
VIDEO
COMMENTS
I'm new to PowerPoint VBA so please bear with me. I would like to: loop through all the slides on a given pptx, loop through all the shapes on a given slide, find chart shapes; loop through the chart's series collection; set the datalabel color property to dark black. So far I have been able to complete the first 3 tasks but I need help with ...
The best way to do this is to use a loop that can apply the same change to every single slide in the presentation. Below shows how you can accomplish this by adding a transition effect to every PowerPoint slide.
i want to loop through all slides and 1) check if a textbox existss, if not move o the next slide 2) if there is a textbox, copy the text to my excell...
Set pptSlide = Application.ActiveWindow.View.Slide. Set pptObject = ActiveWindow.Selection.ShapeRange. Set pptSlide = ActivePresentation.Slides.Add(5, ppLayoutBlank) Set pptSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank) ppLayoutBlank is just one of a number of available layout options.
I have a slide deck and would like to apply Animations - Appear - On Click to every slide from 2 to the end. Each slide has a title box and then a box holding the paragraphs of text. Is this possible?
You can do something with each slide or go through all slides to find a few slides and do something about with using the code; Dim mySlide as Slide For Each mySlide In ActivePresentation.Slides ' Do something with the current slide referred to in variable 'mySlide' ' Debug.Print mySlide.Name Next Slide
I am using several times for each and for loop in powerpoint vba, to loop all the slides and shapes. for example, For i = Activepresentation.slides(i).count . next i. For i = 1 To ActiveWindow.Selection.ShapeRange.Count . next i. Dim sld as slide . Dim shp as shape . For Each sld In ActivePresentation.Slides . For Each shp in sld.shapes. next ...
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.
TLDR: I want to make an array of slides, that is then looped through. Or how can I correctly add an if/else statement within a for loop in VBA. MORE BACKGROUND: I have a PPT that I have to update every week. This includes changing the "capture date" of each slide. This would be quite simple if they all had the same capture date, but they don't.
You can include whichever slides you want — chosen from all the slides in the presentation or from all the slides in the selection — to construct a slide range. For example, you could construct a SlideRange collection that contains the first three slides in a presentation, all the selected slides in the presentation, or all the title slides ...