How to auto execute a macro when opening a Powerpoint presentation?

While Auto_Open doesn’t run in a PowerPoint presentation, you can fake it. Add a CustomUI part to the presentation, then use the CustomUI OnLoad callback to run code when the presentation opens. The CustomUI part needs no more than just the CustomUI tags.

Get the Custom UI Editor from here: http://openxmldeveloper.org/articles/customuieditor.aspx

Open the presentation in the Custom UI Editor. Insert a CustomUI part from the Insert menu:

Add a Custom UI part

Now enter some simple RibbonX code, like this:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
onLoad="MyOnloadProcedure" >
</customUI>

Now write your on-open procedure:

Sub MyOnloadProcedure()
    MsgBox "Hello"    
End Sub

If you have both this and the Auto_Open procedure in an add-in, Auto_Open runs first.

Full disclosure: while I thought of using this approach and have used it in Excel, I waited until I first encountered it on the PPT Alchemy web site: Run Code When PowerPoint Opens.

Leave a Comment