How to Create a PowerPoint 2010 Add-In using VBA with Custom Buttons in the Ribbon
This tutorial will give you a better idea how to create your custom PowerPoint 2010 Add-Ins using VBA code and creating a custom toolbar in the ribbon so you can call macros. This kind of add-in let you do multiple useful actions for example we can create a tool to export the presentation to PDF, export all the slides in your presentation to images (JPG, PNG) or export the slide content and comments as plain text.
1. Create a Macro-Enabled PowerPoint presentation
The first thing you need to know is that in order to create an add-in for PowerPoint using VBA first you start creating a presentation with macros enabled. Then, once you have the code you can save the file as .pptm. Why? Because if you do not keep the macro-enabled PowerPoint presentation then you won’t be able to edit the code later if you need to apply modifications to the add-in. So, it is a good idea starting to create a pptm file.
You can create it using Office Ribbon Editor or just Microsoft PowerPoint. In this case we have created a new presentation directly from Office Ribbon Editor.
Then you will add a new Custom UI Part to your document. See the figure above to learn more about how to. You can use the right context menu in the Document Explorer pane.
Now, you can create the custom UI XML document. You can insert the sections of this document by using the Toolbox on the left if you can just write it manually (or if you get it from any web page then you can use copy and paste).
Notice we have specified to add a new custom tab named Custom Tab with a group of buttons named Export. Then we have created a button with the label Export HTML which will call ExportHTML macro in VBA.
2. Save, Close the Document and Open it in PowerPoint 2010
Now, you can close the document and open it in Microsoft PowerPoint. Press Alt+F11 to open the VBA editor window and add a new Module to the document.
We will add a very basic macro which will display a Message Box, and later we will replace the content.
Now, if we re-open the presentation document then the new tab in the Ribbon should be displayed. In this case we can see Custom Tab was added to the Ribbon and a new button Export HTML is present.
Once the button is pressed, the macro will be executed. In this case we run a simple MsgBox command as shown in the figure below.
3. Save the add-in as PowerPoint Add-In file (.ppam)
Once you have debugged your code and it is working well, you can save the file as a PowerPoint add-in in order you can install it or share as an add-in with other colleagues within your organization.
How we plan to use this approach? Basically to build new functionality and run macros in PowerPoint. A PowerPoint sharing service may use this approach to easily build an add-in for PowerPoint to let users upload PowerPoint presentations to their website, for example using an API. A blogger who need to embed presentation images can use this approach to export all the PowerPoint slides to images or HTML so the output is easily embeddable in a blog or web page (alternatively you can consider to upload your presentation to SlideOnline).
If you want to learn more about how to create a custom UI using XML in Microsoft Office or PowerPoint 2007/2010 then this answer on Stackoverflow can be very descriptive. It explain the steps required to accomplish all these tasks and run your own commands using custom buttons. If you want a solution for PowerPoint 2007 then this other article may be helpful.
Here is another useful resource if you want to read a tutorial on how to customize the Fluent Ribbon in PowerPoint and MS Office 2007 using XML and Custom UI. It is a great resource for developers and you can learn how to use callbacks, configuring the XML, using COM Add-in to modify the Ribbon, working with existing command-bar and more.