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

前端 未结 3 602
北荒
北荒 2020-12-06 18:49

I have a pretty basic question, but could not find the answer on internet.
In Powerpoint 2010, I have a macro that I would like to be executed everytime the Powerpoint do

3条回答
  •  失恋的感觉
    2020-12-06 19:29

    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:

    Now enter some simple RibbonX code, like this:

    
    
    

    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.

提交回复
热议问题