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 document is opened. How to achieve this ?
Thanks !
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 document is opened. How to achieve this ?
Thanks !
Try to write this function.
Replace the msgbox in your code.
I am using PowerPoint 2016 so I can't speak for earlier versions although the documentation indicates this works for PowerPoint versions 2016, 2013, 2010, 2007. This method DOES NOT require any add-ins or application hooks to handle events.
Reference link: https://support.office.com/en-us/article/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6?ocmsassetID=HA010153889&CTT=1&CorrelationId=ea39d200-aa81-4d6e-8302-afff4c65859e&ui=en-US&rs=en-US&ad=US#ID0EAABAAA=PowerPoint,_PowerPoint_Viewer)
Start PowerPoint from command line and use the /M switch to have PowerPoint run a specified macro when it starts a named presentation file.
The easiest way to do this is to create a shortcut to the PowerPoint application. Then go to the Properties window for the shortcut and select the Shortcut tab. Next, add the /M switch, your presentation file name (including path), and the name of the macro to run (case sensitive and must be part of the presentation) to the end of the Target field. Double-click the shortcut and voila!
Example: My presentation is C:\myPPTpres.pptm and the macro is Run_Slide_Show so I will need to add /M "C:\myPPTpres.pptm" "Run_Slide_Show" to the end of the existing text in the Target field.
Make sure you are running a macro-enabled version of the presentation (in 2016 it has the .pptm extension.)
Important note if you are trying to start a slide show automatically using the macro. Add a delay of one or more seconds at the very beginning of your macro to allow the application to finish its startup sequence. If you do not the slideshow will start but the application will steal focus as it completes its startup, pushing your slideshow to the background.
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:
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.
Assuming the type of macro to be Auto Events related such as Auto_open(), Auto_close(), Auto_print() etc., for powerpoint to execute macros on opening powerpoint file we require Powerpoint Add-Ins to be included or other option could be to save the file as .ppa or .ppam.
For more details and to download the AutoEvents zip file refer the link: http://skp.mvps.org/autoevents.htm