How to Open an Existing PowerPoint File using Excel VBA – 5 Steps
You have a blank PPT file saved in Drive (D:).
Step 1 – Launch the Developer Tab
- Right-click the ribbon.
- Select Customize the Ribbon .
- In Excel Options , go to Customize Ribbon .
- Check Developer in Main Tabs .
The Developer tab will be displayed on the ribbon.
Step 2 – Create a CommandButton
- Go to the Developer tab.
- Click Insert in Controls .
- Select CommandButton in ActiveX Controls .
- Drag your mouse and place the button in the worksheet.
The Visual Basic Editor will be displayed.
Step 3 – Enable the PowerPoint Object Model
- Go to the Tools tab.
- Click References .
- In the References – VBAProject window, check Microsoft PowerPoint 16.0 Object Library .
Step 4 – Use a VBA Code
- Enter the following VBA code:
Step 5 – Final Output
- Go back to your worksheet and click CommandButton1 .
This will open the existing file.
How to Create a PowerPoint File with Excel VBA
- Click Visual Basic in Code to open the Visual Basic Editor . You can also press Alt + F11 .
- Alternatively, right-click the worksheet and go to View Code .
- Select Module in Insert .
- Enter the VBA code below:
- Run the code by clicking RunSub or pressing F5 .
This will create a PowerPoint slide.
Read More: [Solved] Embedded Excel in PowerPoint Not Showing All Data
Download Practice Workbook
Download the workbook and practice.
Related Articles
- How to Link PowerPoint to Excel for Dynamic Data Updates
- How to Embed an Excel File in PowerPoint
- [Fixed!] Problems with Embedded Excel Files in PowerPoint
- How to Link Excel Sheets to PowerPoint
<< Go Back to Excel to PowerPoint | Export Data from Excel | Learn Excel
What is ExcelDemy?
Tags: Excel to PowerPoint
Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio
Leave a reply Cancel reply
ExcelDemy is a place where you can learn Excel, and get solutions to your Excel & Excel VBA-related problems, Data Analysis with Excel, etc. We provide tips, how to guide, provide online training, and also provide Excel solutions to your business problems.
See Our Reviews at
- User Reviews
- List of Services
- Service Pricing
- Create Basic Excel Pivot Tables
- Excel Formulas and Functions
- Excel Charts and SmartArt Graphics
- Advanced Excel Training
- Data Analysis Excel for Beginners
Advanced Excel Exercises with Solutions PDF
AutoMacro: Ultimate VBA Add-in
Read all reviews
Return to VBA Code Examples
PowerPoint VBA Macro Examples & Tutorial
Editorial Team
Reviewed by
Steve Rynearson
In this Article
VBA PDF (Free Downloads)
Save as macro-enabled presentation, enable ‘developer’ tab in the ribbon, create powerpoint macro, powerpoint application, open a new presentation, open an existing presentation, open and assign to a variable, refer to active presentation, save current presentation, close current presentation, useful references, assign existing presentation (by name) to variable, assign active slide to variable, assign slide by index to variable, count number of slides, get slide index number of current slide, add a blank slide to end of slide show, add a slide after current slide, delete a slide, go to a specific slide, loop through all slides, loop through all shapes of active slide, loop through all shapes in all slides, loop through all textboxes of active slide, loop through all textboxes in all slides, copy selected slides to new ppt presentation, copy active slide to end of active presentation, change slide during slide show, change font on all slides in all textboxes, change case from upper to normal in all textboxes, toggle case between upper and normal in all textboxes, remove underline from descenders, remove animations from all slides, save presentation as pdf, find and replace text, export slide as image, resize image to cover full slide, exit all running slide shows, open powerpoint – early binding, open powerpoint – late binding, make application visible, maniplulate powerpoint, close the application, copy from excel to powerpoint, powerpoint vba faqs.
This is a complete guide to automating PowerPoint using VBA (Visual Basic for Applications) Macros. Below you will find many useful examples.
Download our free Microsoft PowerPoint VBA Tutorial! Or VBA Tutorials for other Office Programs!
PowerPoint VBA (Macros) Tutorial
The Presentation with VBA code should be ‘Saved As’ PowerPoint Macro-Enabled Presentation (*.pptm)
You should to enable the Developer tab on the Ribbon before creating VBA code. To do so choose File -> Options then click on ‘Customize Ribbon’ and check the box next to ‘Developer’ tab in the right pane.
This is a simple example of a PowerPoint VBA Macro:
It saves the active presentation as a PDF. Each line of code does the following:
- Creates variables for the PowerPoint name and PDF name
- Assigns the active presentation name to pptName variable
- Creates the full PDF name
- Saves the presentation as a PDF
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.
To open a new and blank presentation use the Add method of Application.Presentations collection
To open a presentation which you have already created, use the Open method of Application.Presentations collection
The code above assumes that the presentation is in the same directory as the PowerPoint Presentation containing the code.
You should assign the presentation you open to a variable so that you can manipulate it as per your requirements.
Use the reference ActivePresentation to manipulate the Presentation active in the GUI when the VBA code is executed.
The statement below will save the Active Presentation if it was saved before. It it has not been saved then you will be prompted with the ‘Save As’ dialog.
The statement below will close the Active Presentation even if it was not saved after the last edit.
You can move a slide from its old position to the new position
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;
The power of PowerPoint can be realized by using ‘Shapes.’ The code below loops through all the shapes on the current slide so that you can manipulate them as you want;
You can loop through all the shapes in the presentation by adding a loop to go through all slides.
TextBoxes are the most often used Shape in PowerPoint presentations. You can loop through all the Text Boxes by adding a check for ‘Shape Type.’ TexBoxes have the shape type defined as the VBA constant msoTextBox (the numerical value of the constant is 17)
Again, you can loop through all the textboxes in the presentation by adding a loop to go through all slides.
To copy certain slides to a new presentations, first select the desired slides in the existing presentation and then run the code below;
Useful PowerPoint Macro Examples
Here are some useful macro examples showing how to do tasks. These will also demonstrate the concepts described above.
In typography, a descender is the portion of a letter that extends below the baseline of a font. In most fonts, descenders are reserved for lowercase characters such as g, j, q, p, y, and sometimes f.
When you underline text, it does not look nice under descenders. Here is the code to remove underline from all such characters g, j, p, q, and y in the whole Presentation.
Use the code below to remove all animations set in a Presentation.
You can easily save Active Presentation in PDF format.
You can find and replace text in All TextBoxes of All Slides. After the fist instance of the text you want to find (defined by findWhat) you need to loop through the Find command to find other instances, if any.
You can export Current SLide (or any other slide) as a PNG or JPG (JPEG) or BMP image.
If you have multiple Slide Shows open at the same time then you can close all of them using the macro below.
Automating PowerPoint from Excel
You can also connect to PowerPoint though other applications (like Excel and Word). As as first step, you must refer to an instance of PowerPoint.
There are two ways of doing it – early binding and late binding .
In ‘Early Binding’ you must explicitly set a reference to ‘Microsoft PowerPoint 16 Object Library’ (for MS Office 2019) in the VBE (Visual Basic Editor) using the option Tools->References.
In ‘Late Binding’ application variable is declared as an object and VBA engine connects to the correct application at run time.
After setting the reference to PowperPoint application, you may need to make it visible.
You can use all the methods to manipulate presentations, from within PowerPoint, described above from Excel by just adding the reference to PowerPoint created by you above.
For example
has to be used liked this
Once you have completed what you wanted to do with the PowerPoint application you must close it and should release the reference.
This code will copy a range from Excel to PowerPoint:
Note : It has been kept as simple as possible to show how a range from Excel can be copied to PowerPoint using VBA.
What are macros in PPT?
A Macro is a general term that refers to a set of programming instructions that automates tasks. PowerPoint (PPT) Macros automate tasks in PowerPoint using the VBA programming language.
How do I use VBA in PowerPoint?
To use VBA in PowerPoint, open the VBA Editor (ALT + F11 or Developer > Visual Basic).
How do I create a Macro in PowerPoint?
1. Open the VBA Editor (ALT + F11 or Developer > Visual Basic) 2. Go to Insert > Module to create a Code Module 3. Type ‘Sub HelloWorld’ and press Enter 4. In between the lines ‘Sub HelloWorld’ and ‘End Sub’, type ‘MsgBox “Hello World!’ 5. You’ve created a Macro! 6. Now press ‘F5’ to run the Macro
Written by: Vinamra Chandra
VBA Code Examples Add-in
Easily access all of the code examples found on our site.
Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.
(No installation required!)
Free Download
AutoMacro: VBA Add-in with Hundreds of Ready-To-Use VBA Code Examples & much more!
Empty |
- Excel Courses
- Free Excel Courses
- Excel Video Tutorials
- Excel Keyboard Shortcuts
Premium Excel Course Now Available!
Build professional - unbreakable - forms in excel, 45 tutorials - 5+ hours - downloadable excel files, open a powerpoint presentation from excel, where to install the macro: module.
'Opens a PowerPoint Document from Excel
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application") objPPT.Visible = True
'Change the directory path and file name to the location 'of your document
objPPT.Presentations.Open "C:\test.ppt"
Excel VBA Course - From Beginner to Expert
200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides
Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)
View Course
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press " Alt + F11 " - This will open the Visual Basic Editor - Works for all Excel Versions. Or For other ways to get there, Click Here . For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon . Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here) , click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE) . Select the sheet in which you want the macro to run and double-click that sheet.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
200+ Video Lessons 50+ Hours of Video 200+ Excel Guides
Complete VBA tutorial to interact with Power point Presentations – Part – 1
Excel macro tutorial.
[fusion_text] D
ear Friends,
First of all, I apologize for not responding to many of your questions around dealing with PowerPoint presentations through Excel Macro. Many of you have sent me so many questions around this topic. Questions, which were, mostly, asked were like –
Sample List of Questions…
VBA code to create a presentation slide based on a Table in Excel Excel macro to create a Slide with Graph and Table in Excel Macro to paste Graph from Excel in to a PPT in a specific Slide VBA code to remove old graph from a specific slide and place the new generated graph in Excel – Like refresh button
This list i just a summary what has been asked so far. Many of the questions were too specific, hence I have not mentioned them here. Therefore, I thought of writing a tutorial (more than a single article) and cover most of the aspects related to interaction with PowerPoint presentations through Exel VBA. Rather putting everything in one article, I am splitting in to more than one article. As part of this tutorial, I am sure, you will learn all the basic things (regular things) to interact with PowerPoint Presentations through Excel VBA. Furthermore, you will have readily available VBA code snippets for all the basic operations, one can perform on Presentations like Open, Close, save, Copy a slide from one Presentation to other, deleting a slide, modifying the content of the slide and so on.. Finally, at the end of this tutorial , you will find a FREE Excel VBA tool to download . Mostly in the next article of this tutorial.
Topics covered in this Article
Click on the links to directly jump to that particular section…
Basics about Power Point Application Object Model in Excel VBA
vba code to create a new presentation (power point presentation file), vba code to add slides in ppt, vba code to save a new ppt – saveas statement, vba code to open an existing presentation file, vba code to save an existing presentation file – save statement, vba code to save and close powerpoint presentation, vba code to delete slides in ppt.
Since we are going to access an application which is out side Microsoft Excel. Therefore to interact with that application you should have a good understanding of Objects and Methods of that application. Here in this article I am NOT going to explain you about all the Objects, Methods and Properties of PowerPoint Application but few of them to make you comfortable. To know all possible Objects, Methods, Properties and their hierarchy you can refer this page: http://msdn.microsoft.com/en-us/library/office/aa213568(v=office.11).aspx .
VBA to Create a New Power Point Application
To start with any operation with any kind of PowerPoint file, you need to create an Object for the application itself. Therefore your code will always start with a statement to create an Object for PowerPoint Application:
As soon as the above line of statements are executed you can see a Power Point File launched which will look like below:
As you can see in the above image only a simple Application is launched. It has no placeholder for presentations and Slides. This is because you have just created an Application Object.
Now we have an Application Object so we can create multiple Presentation File from this.
Above code snippet will add 2 presentations (2 PowerPoint files) as you can see in the below images:
But these presentations will be looking something like below – an Empty Presentations without any Slide in it.
Power Point Presentation Object
As you can see in the above image, there is no slide. Now let us see how to add a slide in a presentation created above.
VBA code to add slides to PowerPoint Presentation
In the above example you had added two new presentations with no slide. As you already know, each presentation file may contain multiple slides in it. That means, a Presentatio Object holds a collection of Slides. This means…You can add slides to Slides collection using .Add method of Slides object (Collection of Slide). Refer the Syntax of this method below
Syntax of .Add Method
.Add method belongs to Slides Object. [highlight color=”yellow”]MyPresentation1.Slides.Add <Index Number> , <Layout of the slide>[/highlight]
Index Number: Slides is basically a collection of all Slide Object, a Presentation has it. Therefore to add a slide in Slides collection, you need to pass the index number which tells the position of the new slide in Slides collection. In simple terms, this indicates the position of your Slide in your PowerPoint Presentation. For example: If you pass Index number as 3 then new slide will be added at 3rd position, no matter how many more slides are there. But if total number of slides are less than 2 and you passed index as 3 then it will throw an error.
Layout of the slide: This basically tells the type of Layout you want for your new slide. There is a list of around more than 20 layout type which you can use it for Power Point 2007. You can pass the exact VBA name of a layout or just an integer number (depending on the version of the Office you have in your computer)
Save & Close PowerPoint Through Excel VBA
Let’s have a look – on how to save and close a power point presentation using Excel VBA. .Save and .Close is the keywords to save and close a presentation respectively. These methods belongs to Presentation Object.
In case you want to save your presentation with a different name or at different location then you can use .SaveAs method. The only difference in both these methods is – For .Save you do not need to provide file path but for .SaveAs it is mandatory to provide the file path. Refer below code.
What did we learn so far?
1. How to create Power Point Application , Presentations and Slides Objects 2. How to create new Power Point Presentations 3. How to add slides to power point presentation 4. How to Save and Close Presentations in Excel VBA
VBA to Create a New Power Point Presentation
As I have explained above, I will club all the lines of code with some more statements together and form a single code which will do the following :
1. Create 2 New Power Point File 2. Add 5 slides in one presentation and 3 in second one. 3. Save these power point presentation files on your desktop
You have learnt above, how to create a new Powerpoint presentation with multiple slides in it, save and close it. Now I will teach you how to open an existing Power Point file using Excel VBA
Excel VBA to open PowerPoint Presentation File
First you need to create a PowerPoint Application object which will actually hold your opened presentation file. If you do not have a valid Power Point Application object then you can not open your presentation file directly.
To open a presentation you can use the below statement:
objNewPowerPoint – is your defined Power Point Application Object FilePath – This is the complete path of the file with file name with file extension
Above statement opens a presentation file which is a Presentation Object. Therefore we should assign this to a unique object so that at any point of program we can refer this presentation uniquely.
Now you can use MyPresentation3 presentation object to add slides to it, delete, save, close etc. same as the above code.
Now let us create an example with everything we learnt so far. In this example, I am going to do the following:
1. open an Existing power point presentation 2. Add a Slide at 3rd position (make sure that the file you choose, has, at least 2 slides other wise it will through as an exception as explained above) 3. Save and close the presentation
Important: Difference between Save and SaveAs
In the first example as well we saved one presentation. But in this example Save is different. If you notice in the first example we had used SaveAs because it was a new file and we have to give a valid path and name to save it but in this example this file is already saved in a particular location with a name from where you have opened it.
Therefore in this case you can simply run the Save command which will save the changes you made in that presentation. But if you still want to save this as a different file name or location you can go ahead with SaveAs command. Save As is same as the save as command in any file.
VBA Code to delete slide from PowerPoint Presentation
.Delete method is used to delete a single slide from Slide collection. This method belongs to a single Slide Object. You must identify a single slide item from Slides collection before deleting it.
pSlides(slideNumber).Delete
pSlides.Item(slideNumber).Delete
pSlides : Variable of Slides type where Slide collection of the presentation stored from which slides has to be deleted
slideNumber : As the name says.. Slide number which you want to delete. Like for 1st Slide – 1, for second – 2 and so on..
Important Point
While adding a new slide, we add it in the collection (Slides), therefore .Add method belongs to Slides collection. But, while deleting a slide, we delete individual slides from the collection, therefore .Delete is a method of Slide object -> (Slides.Item(i))
About the Next Article…
In this article I will cover the following: 1. Create Power Point Presentations by creating the Object using CreateObject keyword. 2. Some Useful and practical Examples
Buy a coffee for the author
Get a FREE e-Book
With over 50,000+ readers and counting Join NOW and get a FREE E-book to download !!
You have Successfully Subscribed!
Download FREE Tools and Templates
There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Feb 9, 2024
In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...
How to Declare a Public Variable in VBA
Feb 3, 2024
While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...
How to Copy content from Word using VBA
As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active...
What is Excel Formula?
Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).
You May Also Like…
How to connect to access database – ado connection string.
Using Excel Macros (VBA) you can connect to any Databases like SQL, Oracle or Access DB. In this Article you will...
ADO RecordCount Property – RecordSet Object
The RecordCount property returns a long value that indicates the number of records in a Recordset object. Many a times...
How to Get Excel version using VBA Code
Feb 2, 2024
Dear Friends, Usually while working on any of the VBA projects, it becomes important for me to first check the version...
Hi, My name is Faiz. I need your help to consolidate multiple ppt slides in a single slide but condition is that multiple name in a excel sheet. how to consolidate according to Name wise(Name is available in excel sheet).plz help me to create this code.
Thanks, Faiz
Hi Faiz, Have you got your answer ? If yes, reply with the code so that others can also learn from yours.
Otherwise attach a sample file with your requirement.
I am getting an run time error while opening ,save as and closing PowerPoint using excel vba. Need help its urgent
thanks in advance
Trackbacks/Pingbacks
- Welcome to LearnExcelMacro.com Interacting with Powerpoint Slides – Tutorial – Part 2 (Last) - […] is a continuation of my previous article about Interaction with Power point Slides using Excel Macro. In my previous…
- Complete VBA tutorial to interact with Power point Presentations - Part - 2 - […] is a continuation of my previous article about Interaction with Power point Slides using Excel Macro. In my previous…
Submit a Comment 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.
Submit Comment
This site uses Akismet to reduce spam. Learn how your comment data is processed .
Join and get a FREE! e-Book
Don't miss any articles, tools, tips and tricks, I publish here
Pin It on Pinterest
How to use VBA in PowerPoint: A beginner’s guide
- Written by: Jamie Garroch
- Categories: PowerPoint productivity , Presentation technology
- Comments: 45
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):
*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:
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 :
You now have a module ready to paste the VBA code into from one of our blog articles :
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:
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:
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:
Saving your file
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 :
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.
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!
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.
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.
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
I did not think it was possible for an external team to get our message so quickly and accurately. You got our messages better than we did, and delivered presentations that were slick and really effective. Guy Shepherd Bouygues
- 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
Excel VBA Open Powerpoint File
- Thread starter gmooney
- Start date Feb 13, 2019
- Tags code end open powerpoint.application ppt
Active Member
- Feb 13, 2019
I am getting the error code "Method of 'Open' of object 'Presentations' Failed on the last line of code before the End Sub: Private Sub MonthlyToplinePPT() ' Opens Presentation.pptx Dim PPT As PowerPoint.Application Set PPT = New PowerPoint.Application PPT.Visible = True PPT.Presentations.Open Filename:="C:\Topline\Topline Writeup.pptx" End Sub Any suggestions?
Excel Facts
Well-known Member
Try this: Code: Sub openppt() Dim PPT As Object Set PPT = CreateObject("Powerpoint.Application") PPT.Visible = True PPT.Presentations.Open Filename:=[COLOR=#333333]"C:\Topline\Topline Writeup.pptx"[/COLOR] Set PPT = Nothing End Sub
DanteAmor, Perfect. Worked like a charm!
I'm glad to help you. Thanks for the feedback.
Similar threads
- tbakbradley
- Aug 17, 2024
- Jul 5, 2024
- Aug 14, 2023
- Feb 1, 2023
- Jul 10, 2023
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
- Skip to primary navigation
- Skip to main content
- Skip to footer
VBA PowerPoint
What Is Excel VBA P owerPoint?
Excel VBA PowerPoint refers to using VBA programming language in Microsoft Excel to automate tasks or perform operations related to Microsoft PowerPoint. With Excel VBA PowerPoint, you can create macros and scripts that interact with PowerPoint to automate tasks such as:
- Creating new PowerPoint presentations, adding slides, setting slide layouts, and populating slides with data from Excel.
- Data transfer between Excel and PowerPoint. It could involve copying charts, tables, or other information from Excel and pasting it into PowerPoint slides.
- Formatting and styling of PowerPoint slides. You can customize fonts, colors, shapes, and other elements to achieve a consistent look across your presentations.
- You can use VBA to control the PowerPoint slideshow, including starting, stopping, etc.
To use VBA in Excel for PowerPoint automation, you typically open the Excel VBA editor , write your VBA code , and execute it within Excel. It can then manipulate PowerPoint through the PowerPoint Object Model, which is a set of objects and methods that allow programmatic control over VBA PowerPoint Online. For example, below, we create a subroutine to open a PowerPoint application.
The PowerPoint app is opened in your system.
Table of contents
How to enable powerpoint object model, how to create powerpoint presentation, important things to note, frequently asked questions (faqs), download template, recommended articles, key takeaways.
- The PowerPoint Object Model is a set of objects and methods that allows programmatic control over PowerPoint.
- It provides a way to manipulate PowerPoint elements (slides, shapes, etc.) through code.
- It allows users to add slides, set layouts, and populate slides with data or content.
- VBA enables seamless data transfer between Excel and PowerPoint.
- Users can copy charts, tables, or other information from Excel and paste it into PowerPoint slides.
- Users can write VBA code to perform specific tasks, such as creating a new presentation, adding slides, and manipulating PowerPoint objects programmatically.
Step 1: Open the Excel WorkBook and click on “Developer tab” on the toolbar.
Select “Visual Basic” in the Workbook. It will open the Excel VBA Editor.
Step 2: On opening the VBA Editor and Module, go to “Tools” > “References.”
It will open a Window.
Step 3: Select “Microsoft Office 16.0 Access Database Engine Object” from the References.
Step 4: Also select “Microsoft PowerPoint 16.0 Object Library.”
Step 5: Click “OK” and close the “References” tab. Now you’ve enabled the PowerPoint Object Model in your Excel Workbook.
See how to create a PowerPoint presentation as shown.
Sub CreatePowerPointPresentation() Dim pptApp As Object Set pptApp = CreateObject(“PowerPoint.Application”) pptApp.Visible = True Dim pptPres As Object Set pptPres = pptApp.Presentations.Add Dim slideIndex As Integer slideIndex = 1 pptPres.Slides.Add slideIndex, ppLayoutText End Sub
8. Run the sub-procedure by either pressing “F5” or the green arrow button on the VBA Editor toolbar to run the sub-procedure.
See some interesting examples of how to create a PowerPoint presentation using Excel VBA.
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.
Step 2: Create a new PowerPont Application instance in VBA using a variable.
Step 3: Set the PowerPoint visibility to true and then Activate the PPT.
Step 4: Create a new PowerPoint presentation in the PowerPoint application.
Step 5: Add a slide to the PowerPoint presentation and set its layout as the Title.
There will be two text boxes on the Title page in which you can write the name.
Step 6: Add the content for the Title Box and the Subtitle Box with the VBA PowerPoint Shapes function.
The text boxes are defined as “Shapes”. So Shape(1) will be the Title Box in the Presentation slide, and Shape(2) will be the Subtitle Box in the PowerPoint presentation.
Step 7: Add another slide into the Presentation with index 2 and set the layout as blank. It will be so that there are no text boxes available.
Sub CreatePowPntShow() Dim ppt As PowerPoint.Application Set ppt = New PowerPoint.Application ppt.Visible = True ppt.Activate Dim pptPres As PowerPoint.Presentation Set pptPres = ppt.Presentations.Add Dim pptSlide As PowerPoint.Slide Set pptSlide = pptPres.Slides.Add(1, ppLayoutTitle) pptSlide.Shapes(1).TextFrame.TextRange = “VBA PowerPoint Tutorial” pptSlide.Shapes(2).TextFrame.TextRange = “by ExcelMojo” Set pptSlide = pptPres.Slides.Add(2, ppLayoutBlank) pptSlide.Select End Sub
Step 8: Run the sub-procedure to create a 2-page PowerPoint presentation, as shown below.
Here, you want to copy the tables from Excel and paste them into PowerPoint. Instead of manually doing it, you can use Excel VBA to copy from the Excel sheet and paste it into the PowerPoint presentation using VBA PowerPoint. This code might look long, but we will break it down into simple steps and explain each line so that understanding it is a breeze! Look at the table below.
Step 1: Name the subroutine that will copy and paste Excel tables into PowerPoint.
Step 2: Define a new PowerPoint Application instance and assign it to an instance variable.
Step 3: Set its visibility as TRUE and activate the instance.
Step 4: Add a new Presentation to which we will copy the table to the activated PowerPoint application.
Step 5: Now, we need a PowerPoint slide object to put the first slide into it. Let us set its layout as the PowerPoint title layout.
Step 6: Define a variable to store the Title textbox using VBA PowerPoint shapes.
Step 7: Write the title text and customize its font, font size, and color, as shown.
Using the VBA With Statement , you can neatly arrange the common functions with the same header to save space.
Step 8: Define a variable to store the subtitle box using the VBA PowerPoint Shapes function.
Step 9: Write the content required in the subtitle box and then customize its font.
Similarly, use the VBA With to group function names with common prefixes together to encourage code readability.
Step 10: Add a second slide to the presentation with the classic text layout of PowerPoint.
Step 11: Write the title and the required points on the slide using VBA PowerPoint shapes.
Step 12: Make slide 2 the active slide by using the VBA PowerPoint active slide.
Step 13: Copy the table from Excel and paste it into the current slide.
Using VBA CurrentRegion will select all non-empty cells at a stretch in an Excel worksheet. Here, it is copied and pasted into the PowerPoint side.
Sub CreatePPointPresentation() Dim PowPntApp As PowerPoint.Application Set PowPntApp = New PowerPoint.Application PowPntApp.Visible = True PowPntApp.Activate Dim PowPntPrsnt As PowerPoint.Presentation Set PowPntPrsnt = PowPntApp.Presentations.Add Dim PowPntSlide As PowerPoint.Slide Set PowPntSlide = PowPntPrsnt.Slides.Add(1, ppLayoutTitle) ‘ Content for title and its customization Dim titleShape As PowerPoint.Shape Set titleShape = PowPntSlide.Shapes(1) titleShape.TextFrame.TextRange.Text = “Information on Employees” With titleShape.TextFrame.TextRange.Font .name = “Montserrat” .Size = 40 .Bold = True .Color.RGB = RGB(240, 0, 120) ‘ Set font color to pink End With ‘ Content for subtitle box and its customization Dim subtitleShape As PowerPoint.Shape Set subtitleShape = PowPntSlide.Shapes(2) subtitleShape.TextFrame.TextRange.Text = “by VBATutorials” With subtitleShape.TextFrame.TextRange.Font .name = “Calibri Bold” .Size = 30 .Color.RGB = RGB(128, 0, 200) End With ‘ Add a blank slide Set PowPntSlide = PowPntPrsnt.Slides.Add(2, ppLayoutText) PowPntSlide.Shapes(1).TextFrame.TextRange.Text = “EMPLOYEES IN TUTORIAL” PowPntSlide.Shapes(2).TextFrame.TextRange.Text = “Information on Employees” PowPntSlide.Select ‘ Copy data from Excel and paste it as a table Range(“A1”).CurrentRegion.Copy PowPntSlide.Shapes.Paste End Sub
Step 14: Run the subroutine to see the PowerPoint presentation.
- Explicitly close and release PowerPoint objects (e.g., presentations, slides) when you’re done using them to free up system resources.
- Minimize the use of Select and Activate in your code.
- Avoid hardcoding values when possible. Use variables or constants to make your code more flexible and easier to update.
- Avoid suppressing warnings without a good reason. Disabling warnings can hide potential issues that need attention.
Yes, it’s possible to interact with Excel from PowerPoint using VBA. Use the CreateObject function to create an Excel Application object. You can then manipulate Excel objects, transfer data, and perform tasks. Remember to release the Excel object when done as shown. Dim slideIndex As Integer For slideIndex = 1 To ActivePresentation.Slides.Count ‘ Your code here Next slideIndex
Yes, it’s possible to interact with Excel from PowerPoint using VBA. Use the CreateObject function to create an Excel Application object. You can then manipulate Excel objects, transfer data, and perform tasks. Dim xlApp As Object Set xlApp = CreateObject(“Excel.Application”) ‘ Your code to interact with Excel here Set xlApp = Nothing
By declaring the following code, you can assign a macro to a button or shape. ActiveSheet.Shapes(“YourButtonName”).ActionSettings(ppMouseClick).Action = “YourMacroName”
Using VBA On Error Resume Next and On Error GoTo 0, you can disable potential errors that may come out of a few lines of code. On Error Resume Next ‘ Your code that might cause an error On Error GoTo 0 ‘ Reset error handling to default ‘ Check for errors using Err object: If Err.Number <> 0 Then ‘ Your error-handling code here End If
This article must help us understand the VBA PowerPoint formula and examples. You can download the template here to use it instantly.
Guide to VBA PowerPoint in Excel & its meaning. Here we explain how to use the VBA PowerPoint with its properties, adding module, examples & downloadable excel template. You can learn more from the following articles –
- VBA GetObject
- VBA CreateObject
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.
- Privacy Policy
- Terms of Service
- Excel Guides
- Power BI Guides
- Tableau Guides
- Google Sheets
How To Open VBA In PowerPoint
Have you ever wondered what VBA is and how you can use it in PowerPoint?
From opening VBA in PowerPoint to creating basic commands and utilizing tips and tricks, this article will guide you through the process step by step.
Key Takeaways:
What is vba.
VBA , short for Visual Basic for Applications, is a programming language developed by Microsoft for automating tasks in Microsoft Office applications.
Why Use VBA in PowerPoint?
Utilizing VBA in PowerPoint can significantly boost productivity and efficiency by providing an automation service for repetitive tasks.
This level of automation not only saves time but also reduces the likelihood of oversight, resulting in smoother operations and increased output quality in a shorter timeframe.
How to Open VBA in PowerPoint?
Step 1: open the powerpoint presentation.
By launching your PowerPoint presentation first, you set the stage for seamless integration of Visual Basic for Applications (VBA), a powerful programming language that allows you to automate tasks, manipulate presentations, and enhance interactivity. Working within the PowerPoint environment is crucial as it provides direct access to all the tools and functionalities you need to create dynamic and customized presentations.
Step 2: Enable the Developer Tab
Step 3: access the visual basic editor.
After enabling the Developer tab, navigate to the Visual Basic Editor in Microsoft PowerPoint to start coding and creating VBA modules.
Step 4: Create a New Module
In the Visual Basic Editor, create a new module in the module window or project explorer pane to begin coding and organizing your VBA scripts.
Step 5: Start Coding with VBA
When diving into coding in VBA for your PowerPoint project, the process typically involves accessing the Visual Basic for Applications Editor, where you can input specific code snippets to create the desired functionalities. It’s crucial to have a clear understanding of the VBA language syntax and PowerPoint object model to effectively integrate the code snippets. Leveraging external resources like BrightCarbon can provide valuable insights, tips, and best practices on writing efficient and optimized code, ultimately enhancing your automation and customization capabilities.
Basic VBA Commands for PowerPoint
Adding and formatting text.
Using VBA in PowerPoint, you can enhance your presentations by adding and formatting text dynamically to create visually appealing slides.
Adding and Editing Shapes
With VBA, you can not only insert basic shapes such as rectangles, circles, and arrows, but also have the flexibility to customize them with specific properties like size, color, and position. This level of control enables you to precisely tailor the appearance of each shape to suit your presentation needs.
Adding and Manipulating Images
VBA provides users with a powerful set of tools that can automate image tasks, such as resizing, cropping, and applying filters, saving you valuable time and effort during the creation process. By leveraging VBA scripts, you can seamlessly integrate images into your slides, ensuring a cohesive and professional look throughout your presentation.
Creating Animations and Transitions
With VBA’s automation capabilities, you can create intricate sequences that not only captivate your audience but also help reinforce key points and maintain their attention throughout your presentation.
Tips and Tricks for Using VBA in PowerPoint
To ensure the security of your PowerPoint files, enforce password protection and restrict access to sensitive information. Consider digitally signing your macros to prevent unauthorized tampering. This dual focus on functionality and security will optimize your experience with VBA in PowerPoint.
Use Macros for Repetitive Tasks
The real power of VBA macros lies in their ability to execute complex sequences of commands with just a single click, reducing the chances of manual errors and oversight. This level of automation not only saves time but also frees up users to focus on more creative aspects of their presentations.
Utilize Variables and Loops
Debugging and troubleshooting.
Master the art of debugging and troubleshooting in VBA for PowerPoint to identify and resolve coding issues effectively, ensuring smooth functionality.
Explore Online Resources and Communities
Broaden your VBA knowledge by tapping into online resources and communities like BrightCarbon and Jamie Garroch’s platform to access code snippets, tips, and best practices.
Frequently Asked Questions
1. how do i access vba in powerpoint, 2. can i customize my vba editor in powerpoint.
Yes, you can customize your VBA editor in PowerPoint by going to the “Options” menu within the editor. From there, you can change the font, enable syntax highlighting, and more.
3. Why do I need to use VBA in PowerPoint?
4. how can i learn vba in powerpoint, 5. can i use vba in powerpoint on a mac.
Yes, VBA is available on both Windows and Mac versions of PowerPoint. However, the functionality and features may differ slightly between the two versions.
6. Are there any precautions I should take when using VBA in PowerPoint?
Similar posts, how to highlight in powerpoint, how to embed video in powerpoint without quicktime, how to make jumbled words in powerpoint, how to make a shape transparent in powerpoint, how to change master header in powerpoint, how to embed html in powerpoint.
How to Open and Use VBA Macro Editor in PowerPoint
Are you tired of manually performing repetitive tasks in PowerPoint? Look no further than the open VBA Macro editor in PowerPoint 2021. Whether you’re a seasoned PowerPoint user or just getting started, understanding how to use the VBA Macro editor can drastically improve your workflow.
Table of Contents
What is vba, steps to open the vba macro editor.
1. Create a new presentation or open an existing one. Then go to the File tab and click on Options .
4. In the VBA Macro editor, you can see the Project Explorer pane on the left, which shows all the modules and objects in your presentation. You can also see the Code window on the right, where you can write and edit your VBA code.
7. To create a new macro, type Sub followed by a name for your macro in the Code window. For example, Sub HelloWorld() . Then press Enter and type End Sub on a new line. This will create a basic macro structure with a name and an empty body.
10. You should see a message box with the text “Hello World” appear on your screen.
How do I open the VBA editor in PowerPoint?
You may also enable the Developer tab. Go to Developer > Macros . Select the macro and click Run .
How do I edit VBA code in PowerPoint?
How do i create a new vba module in powerpoint.
How can I assign a keyboard shortcut to run a macro in PowerPoint?
To assign a keyboard shortcut to a macro in PowerPoint, first create the macro and write the VBA code. Then go to the File > Options > Customize Ribbon . In the box on the left, select Macros . Then select the macro you want to assign a shortcut to from the list on the right.
How can I debug VBA code in the PowerPoint editor?
First, I open the Visual Basic editor by pressing Alt+F11 . Then I set breakpoints in my code by clicking in the left margin of the line numbers. When I run the code with F5 , it will pause execution at any breakpoint I set so I can step through my code line-by-line with F8 and inspect variables.
About The Author
Rully novrianto, related posts, guide to cite a powerpoint in apa.
Create Awesome Excel & PowerPoint Charts with ChartChooser
How to Create a Chalkboard Background in PowerPoint
How to do a double exposure effect on powerpoint.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Presentation.Close method (PowerPoint)
- 7 contributors
Closes the specified presentation.
expression . Close
expression A variable that represents a Presentation object.
When you use this method, PowerPoint will close an open presentation without prompting the user to save their work. To prevent the loss of work, use the Save method or the SaveAs method before you use the Close method.
This example closes Pres1.ppt without saving changes.
This example closes all open presentations.
Presentation Object
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
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
- OverflowAI GenAI features for Teams
- OverflowAPI Train & fine-tune LLMs
- Labs The future of collective knowledge sharing
- About the company Visit the blog
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Get early access and see previews of new features.
How can I programmatically open Powerpoint without seeing the window?
I have this script, made by another user
It opens the input file, converts it to a .pdf and saves it as the output file.
However, PowerPoint also opens, and I see the actual window load up.
This process is going to be running on a server, so I figure that loading up the GUI every time a user wants to convert something is going to be unnecessarily resource intensive.
Is there any way to programmatically open PowerPoint without the GUI popping up?
I've tried replacing
objPPT.Visible = True with
objPPT.Visible = False
But that throws an error telling me that it cannot be that way.
I've also tried replacing
objPPT.Presentations.Open inputFile with
objPPT.Presentations.Open inputFile,,,msoFalse
But that gives me an error saying:
Microsoft PowerPoint 2013: Application.ActivePresentation : Invalid request. There is no active presentation.
The error is triggered from the Set objPresentation = objPPT.ActivePresentation line.
From doing some research about the subject, I found that some people have success by using the Open method
The fourth parameter is WithWindow . Theoretically, this should open the presentation without a window if set to false.
But whatever I do to it doesn't seem to work.
WithWindow:= false gives me a syntax error
I found out about OpenXML, and I'm looking into that.
- IIRC you can't automate PowerPoint without a visible window. – Ansgar Wiechers Commented Sep 6, 2013 at 22:29
- 1 Ansgar, that's not correct. You can definitely automate it w/o visible window, but you can't call certain methods if you do. – Steve Rindsberg Commented Sep 8, 2013 at 18:16
2 Answers 2
It needs another comma
The parms are:
You're telling it to open the input file, read-only, not untitled and leaving the WithWindow parm at its default value (True) which opens WITH a visible window.
Bear in mind that you can't write any code that selects anything (that requires a visible window), but since you're not doing this, you should be good to go.
[APPENDED EDITS] Ansgar's correct (apologies for my earlier mistaken comment). We're not allowed to invoke PPT invisibly, BUT if you create/open a presentation windowlessly, PPT never appears. I'm not familiar enough with VBS scripting to work out the exact problem you're seeing, but have test this VBA in PPT 2013/Win8 and PPT 2010/Win7. New slides get added to the presentation w/o PPT ever appearing.
- When I tried that, I get an error from Powerpoint that says Microsoft PowerPoint 2013: Applicatio n.ActivePresentation : Invalid request. There is no active presentation. – user773737 Commented Sep 8, 2013 at 19:36
- The error is triggered from the Set objPresentation = objPPT.ActivePresentation line. – user773737 Commented Sep 9, 2013 at 14:48
- Please update to: objPresentation = oApp.Presentations.Open(ppt_file, , , Microsoft.Office.Core.MsoTriState.msoFalse) – Alaa Sadik Commented May 19, 2020 at 23:19
Open with hidden ppt App window
Your Answer
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Sign up or log in
Post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .
- The Overflow Blog
- Where developers feel AI coding tools are working—and where they’re missing...
- He sold his first company for billions. Now he’s building a better developer...
- Featured on Meta
- User activation: Learnings and opportunities
- Preventing unauthorized automated access to the network
- Should low-scoring meta questions no longer be hidden on the Meta.SO home...
- Announcing the new Staging Ground Reviewer Stats Widget
Hot Network Questions
- Undamaged tire repeatedly deflating
- Better way to share JavaScript code
- What should you list as location in job application?
- What Greek word is in 1 John 4:18; torment, punishment, restraint, trauma, after saying ‘perfect love casts out fear, for fear has to do with…’ what?
- How can the doctor measure out a dose (dissolved in water) of exactly 10% of a tablet?
- Can a floppy disk be wiped securely using the Windows format command with the passes-parameter?
- Azure SQL Database CLR functions are working
- Expected value of a matrix = matrix of expected value?
- Short story about a space traveller on a planet of people, each immensely talented
- Double 6x6 Beam
- How was the year spoken in late 1800s England?
- Is it even possible to build a beacon to announce we exist?
- When can I book German train tickets for January 2025?
- Is it common in modern classical music for timpani to play chromatic passages?
- What is the smallest interval between two palindromic times on a 24-hour digital clock?
- How can I draw a wedge of a cylinder?
- FIFO capture using cat not working as intended?
- Sticky goo making it hard to open and close the main 200amp breaker
- An everyday expression for "to dilute something with two/three/four/etc. times its volume of water"
- Draw a part of a sphere
- What is the mechanical equivalent of an electronic AND gate?
- How do I link a heading containing spaces in Markdown?
- Why do (some) LaTeX fonts have separate 8pt and 10pt font files?
- Were Soviet doctors and nurses actually as callous as "Voices from Chernobyl" portrays in the prolog?
COMMENTS
Opens the file with read/write status. Opens the file with read-only status. The Untitled parameter value can be one of these MsoTriState constants. The default. The file name automatically becomes the title of the opened presentation. Opens the file without a title. This is equivalent to creating a copy of the file.
Dim myPresentation As PowerPoint.Presentation Dim PowerPointApp As PowerPoint.Application PowerPointApp.Presentations.Open Filename:="obscured filepath and name"` Obviously there's some additional code, but I'm trying to set the Presentation I just opened in line 3 set to the MyPresentation variable so I can reference the document I just opened.
How to Create a PowerPoint File with Excel VBA. STEPS: Click Visual Basic in Code to open the Visual Basic Editor. You can also press Alt + F11. Alternatively, right-click the worksheet and go to View Code. Select Module in Insert. VBA Code: Dim PwrApp As PowerPoint.Application. Dim PwrPre As PowerPoint.Presentation.
Use Presentations (index), where index is the presentation's name or index number, to return a single Presentation object. The following example prints presentation one. Presentations(1).PrintOut Use the Open method to open a presentation and add it to the Presentations collection. The following example opens the file Sales.ppt as a read-only ...
The code above assumes that the presentation is in the same directory as the PowerPoint Presentation containing the code. Open and Assign to a Variable. You should assign the presentation you open to a variable so that you can manipulate it as per your requirements. Dim ppt As Presentation Set ppt = Presentations.Open("My Presentation.pptx")
Office VBA reference topic. Remarks. For information about using events with the Application object, see How to: Use Events with the Application Object.. If your Visual Studio solution includes the Microsoft.Office.Interop.PowerPoint reference, this event maps to the following types:. Microsoft.Office.Interop.PowerPoint.EApplication_PresentationOpenEventHandler (the PresentationOpen delegate.)
How to Install the Macro. Select and copy the text from within the grey box above. Open the Microsoft Excel file in which you would like the Macro to function. Press " Alt + F11 " - This will open the Visual Basic Editor - Works for all Excel Versions. Or For other ways to get there, Click Here.
To open a presentation you can use the below statement: objNewPowerPoint.Presentations.Open("filepath") Where : objNewPowerPoint - is your defined Power Point Application Object FilePath - This is the complete path of the file with file name with file extension. Above statement opens a presentation file which is a Presentation Object.
With PowerPoint open and at least one presentation file open, press Alt+F11* on your keyboard. This will open the VBE (Visual Basic Editor): *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 ...
Excel VBA Open Powerpoint File. Thread starter gmooney; Start date Feb 13, 2019; Tags code end open powerpoint ... Dim PPT As Object Set PPT = CreateObject("Powerpoint.Application") PPT.Visible = True PPT.Presentations.Open Filename:=[COLOR=#333333]"C:\Topline\Topline Writeup.pptx"[/COLOR] Set PPT = Nothing End Sub . Upvote 0.
It will open the Excel VBA Editor. Step 2: On opening the VBA Editor and Module, go to "Tools" > "References.". It will open a Window. Step 3: Select "Microsoft Office 16.0 Access Database Engine Object" from the References. Step 4: Also select "Microsoft PowerPoint 16.0 Object Library.". Step 5: Click "OK" and close the ...
Add this to your module (aircode, may need debug help): Function PPTFileIsOpen(pptApp as object, sFullname as string) as boolean. Dim x as long. For x = 1 to pptApp.Presentations.Count. if pptApp.Presentations(x).fullname = sFullname ) Then. PPTFileIsOpen = True. Exit Function. end if. Next.
To access VBA in PowerPoint, you need to enable the Developer tab and access the Visual Basic Editor through the Customize Ribbon menu in Microsoft PowerPoint. Begin by opening Microsoft PowerPoint on your computer. Ensure that you have a PowerPoint presentation open. Next, click on the 'File' tab located at the top left corner of the ...
Steps to open the VBA macro editor. 1. Create a new presentation or open an existing one. Then go to the File tab and click on Options. 2. Click on Customize Ribbon, and check the box next to Developer and click OK. 3. Go to the Developer tab and click on Visual Basic. Another way is to press Alt + F11 on your keyboard.
DestinationPPT = DestinationPPT & "\Gemba Template.pptx". Set PowerPointApp = CreateObject("PowerPoint.Application") Set myPresentation = PowerPointApp.Presentations.Open("DestinationPPT") 'Transition from Excel to PowerPoint. Dim x, lastRow, slideNum As Integer. Dim cellName, shapeName, cellScore As String. vba.
expression A variable that represents a Presentation object. Remarks. When you use this method, PowerPoint will close an open presentation without prompting the user to save their work. To prevent the loss of work, use the Save method or the SaveAs method before you use the Close method. Example. This example closes Pres1.ppt without saving ...
If Len(f) = 0 Then MsgBox "No matching file found", vbExclamation Exit Sub End If Set sourcePres = Presentations.Open(sourcePath & f) 'Open ppt file and get a reference sourcePres.Slides(1).Copy thisPres.Slides.Paste 'you can add a paste position here, or leave blank to paste to the end...
From doing some research about the subject, I found that some people have success by using the Open method. The fourth parameter is WithWindow. Theoretically, this should open the presentation without a window if set to false. But whatever I do to it doesn't seem to work. WScript.Stdout.WriteLine strLine.