Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

FREE PPTools add-ins like THOR - The Hammer!, ImageInsert, Narrator, SelectionManager and more

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Create an ADD-IN with Ribbon buttons that run macros when clicked

When Microsoft introduced Office 2007, they created a totally new user interface that requires a totally new way of adding customizations (ie, new buttons that run macros) to PowerPoint.

Actually, the old way of doing things still works reasonably well. When you write code to create command bars with buttons as explained in Create an ADD-IN with TOOLBARS that run macros, PowerPoint 2007 and later add a new Add-Ins tab to the ribbon and create any requested command bars and buttons there.

But if you want to take advantage of the new Ribbon interface, you'll need to do things a bit differently. You'll need to write special XML code to define the buttons you want to create, what tabs they appear on and what subroutines they'll run when the user clicks them.

Before we get into the details, let me recommend RibbonX: Customizing the Office 2007 Ribbon (Ken Puls/Robert Martin/Teresa Henning). While you can find a lot of the material in this book on the internet, you won't find it so neatly packaged and organized nor will you find a clearer or more complete reference. If you plan to do more than the simplest possible Ribbon customizations, do yourself a favor: get this book. While the title mentions Office 2007, all of the information applies equally well to all later Windows versions and the more recent Mac versions.

Overview

Let's assume that you've already created and debugged your add-in and are ready to put a friendly, modern face on it.

Create and add XML to your project

You can create RibbonX in Notepad and use Windows to unzip your PPTM, add the XML to it, and re-zip it. And you can remove your own wisdom teeth with a hammer and pliers.

I wouldn't wish either upon you, and won't offer "how-to" instructions here. Not when there's a kinder, gentler (and much more efficient) way.

You'll want to download the Custom UI Editor tool (see link below) or one of the other available RibbonX XML editors. They'll validate your XML for you and make sure that it's popped automatically into the correct part of your PPTM/PPAM files.

In case you don't already have working add-in code, here's a simple sample. Create a presentation, add this VBA code to it and save it as a PPTM, then close the file.

Public Sub RibbonXDemo_BUTTON_One()
' This just tells you how many slides are in the current presentation

    Dim oPres As Presentation

    If Presentations.Count < 1 Then
        MsgBox "Please open a presentation and try again."
        Exit Sub
    End If

    Set oPres = ActivePresentation

    MsgBox "Button_One says that there are: " & CStr(oPres.Slides.Count) & " slides."

End Sub   '  BUTTON_One

Public Sub RibbonXDemo_BUTTON_Help()
' This one's even more useless than the first
    MsgBox "Help?  HELP???  At these prices, you expect HELP?????"
End Sub

Then open the PPTM in the Custom UI Editor tool or another RibbonX editor and add this XML:

<!-- This adds a new group to the Design tab and adds a couple of buttons to the group -->
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<ribbon>
  <tabs>
    <tab idMso="TabDesign">
	
      <group id="RibbonXDemo_Group_RibbonXDemo" 
      label="RibbonX Demo" 
      insertAfterMso="GroupPageSetup">
					
        <button 
          id="RibbonXDemo_Button_One" 
          label="Button One" 
          size="normal" 
          imageMso="DrawingCanvasExpand"
         onAction="RibbonXDemo_Button_One"
         screentip="Do whatever Sub RibbonXDemo_Button-One says to do"
         />

        <button 
          id="RibbonXDemo_Button_Help" 
          label="Help" 
          size="normal" 
          imageMso="Help"
          onAction="RibbonXDemo_Button_Help"
          screentip="Help me! Help me! HELP!!!"
         />

      </group>
    </tab>
  </tabs>
</ribbon>

</customUI>

Save and close the file. Open it again in PowerPoint and click the Design tab. If you've done everything right, there'll be a new RibbonX Demo group to the right of the Page Setup group. The new group will have two buttons. Hover the mouse cursor over them to see the tooltip text, and click them to see what they do (not much, just as promised).

Tricks, Tracks, Tips

Give your subroutines unique names

You'll notice that the names of the IDs, buttons and subroutines in both the XML and the VBA all start with the same "RibbonXDemo_" prefix.
It's a good idea to make these names unique. If you use the same name ( Sub Help for example) in several different add-ins, or if someone else has used the same name in their add-in, PowerPoint may run the wrong code when your Ribbon button is clicked.

XML in a PPTM vs PPAM

By now, you've probably noticed that your new custom group on the Design tab and all of its buttons disappear when you close the file containing the XML and VBA. This may be useful under some circumstances, but generally, no.

You'll probably want to save the file as an add-in:
Choose File | Save As | Save as type: | PowerPoint Add-In (*.PPAM)

Don't choose PowerPoint 97-2003 Add-in (*.PPA). The add-in will still work but there won't be any RibbonX code in it. No RibbonX code, no buttons to click, so no way to RUN the code. (Well. Strictly speaking, there may be, but it's not very practical, so let's pretend that there's not.)

Now you can close the file and use File | PowerPoint Options | Add-Ins to load the newly saved add-in. Your custom group and its buttons will re-appear and will become a permanent part of PowerPoint until you choose to remove the add-in again.

RibbonX editors and other resources


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2023 Stephen Rindsberg dba PPTools and the MS PowerPoint MVP team.
You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Create an ADD-IN with Ribbon buttons that run macros when clicked
http://www.pptfaq.com/FAQ01216-Create-an-ADD-IN-with-Ribbon-buttons-that-run-macros-when-clicked.htm
Last update 20 June, 2023
Created: 21 May, 2015