Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add tabs to PowerPoint 2010 that call macros

I have created a pptm file with macros that open certain pptx templates. I then created a new tab with buttons for opening the files. I attached the macros I created to those buttons. All works great as long at my pptm file is open. But after I save it as a ppam file and install it as an add-in it no longer works. It seems the macros don't come along and the buttons are still trying to reference the macros via the pptx name.

Does anyone know a simple way to create a custom tab to launch predefined templates? Or load macros by default like Word does? Or fix my situation above? The only alternative I see is an add-in that will only show up under the Add-In's tab.

like image 678
JoelCool Avatar asked Oct 05 '10 20:10

JoelCool


People also ask

Can I Record Macro in PowerPoint?

To record a powerpoint macro: In the menu bar, click on Tools. Mouse over Macro > and the submenu will be displayed. Click the Record button - a new toolbar will be displayed.


1 Answers

Are you manually creating the ribbon with the buttons? I use the Custom UI Editor Tool and it works like a charm.

  1. Just create any macro in your .pptm, like this:

    Sub SayHello(ByVal control As IRibbonControl)
        MsgBox "hello"
    End Sub
    

    The (ByVal control As IRibbonControl) part is important.

  2. Then save and close your .pptm.

  3. Open the Custom UI Editor Tool. From that tool, click Open from the File menu and navigate to your .pptm and open it.

  4. On the Insert menu, click Office 2010 Custom UI Part. This will create a new XML document that will be inserted into your .pptm.

  5. You can then use sample snippets to start creating your ribbon, but the simplest is just from the Insert | Sample XML menu, just click on Custom Tab. This will insert:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
        <ribbon startFromScratch="false">
            <tabs>
                <tab id="customTab" label="Custom Tab">
                    <group id="customGroup" label="Custom Group">
                        <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
                    </group>
                </tab>
            </tabs>
        </ribbon>
    </customUI>
    

    Where you see Callback in after onAction, replace it with the name of your macro. In our example above, it is SayHello, so it should now look like onAction="SayHello".

  6. Click Save and then close the Custom UI Editor Tool.

  7. Open your .pptm in PowerPoint and test that a tab called Custom Tab has been created. Navigate to it and click on the happy face button. You should now get a message box.

  8. Go to the Backstage by clicking on File and click Save As... and then choose as the file type PowerPoint Add-in (*.ppam) and save it in any location. Note the location.

  9. Go to File | Options | Add-in and then select PowerPoint Add-ins from the Manage dropdown at the bottom of the dialog. Then click Go. Click **Add New...* and add your add-in from the location you saved it.

  10. Close PowerPoint and reopen it. The Custom Tab ribbon should be there. Click on the happy face icon to run your SayHello macro.

The only thing you'll need to do beyond this is to customize your macros and ribbon controls they way you need them and for what you want them to do. Check out this link for more info: Customizing the 2007 Office Fluent Ribbon for Developers

like image 61
Todd Main Avatar answered Dec 09 '22 23:12

Todd Main