2

I'm trying to write a macro which gets automatically executed when I open my PowerPoint presentation in PowerPoint 2013. According to this article, and this StackOverflow answer this can be done with writing a VBA subroutine with the name "Auto_Open":

Sub Auto_Open()
   MsgBox ("Hello World!")
End Sub

I guess, this is a very basic stuff, but still this doesn't work for me. In the Trust center, I enabled all macros, and the "Trust access..." is also checked in.

I'm using PowerPoint 2013. Is it possible that Microsoft doesn't support auto macros in PowerPoint 2013? I haven't found any info about this on the internet, only for Word 2013.

Community
  • 1
  • 1
Zsolt
  • 3,263
  • 3
  • 33
  • 48
  • You may find the [Getting Started with VBA in PowerPoint 2010](https://msdn.microsoft.com/en-us/library/office/ee814734%28v=office.14%29.aspx?f=255&MSPPError=-2147217396) article helpful. – Eugene Astafiev May 22 '15 at 08:31
  • My subroutine works. I can run it manually. It just doesn't get executed automatically when I open the file. – Zsolt May 22 '15 at 08:35
  • You need to have an event to detect the opening, but I was looking in PPT 2010 and I didn't found what I was expecting (something like Excel or Outlook), so I'm starting to doubt that I'll be as easy as for the other apps.... – R3uK May 22 '15 at 09:38
  • I also doubt it is possible. For MS Word it works fine if I create a subroutine called "AutoOpen". – Zsolt May 22 '15 at 09:50

3 Answers3

2

An Auto_Open subroutine will fire automatically when an ADD-IN containing it is loaded, but the same subroutine in a regular PowerPoint file will not run automatically. The article on mvps.org does NOT suggest otherwise; it's about an add-in that traps events and can then call macros that you write, but again, it requires that an add-in be loaded.

An add-in can trap presentation open and other events, and can fire code that checks the presentation to determine whether it should do further processing or not ... IOW, it could check to see if this is your presentation or some random one (that it shouldn't touch).

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
1

It seems to me that there is no simple way to automatically run macros in PowerPoint.

There is a possibility to run the macro using Auto_Open, but with very limited functionality.

1.Create *.pptm file with code:

Sub Auto_Open()
MsgBox "Hello"    
End Sub

2.Save file as Add-in -> *.ppam

3.Open you PowerPoint document and add this add-in

Every time you run PowerPoint will automatically run this add-in. In add-in works Auto_Open :)

Writing about writing about "small functionality" I meant (http://skp.mvps.org/ppafaq.htm#14):

Two macros are fired automatically within an add-in. Auto_Open and Auto_Close. Auto_Open is fired when the add-in is loaded and Auto_Close fired when the add-in is being unloaded. You can use them to do preprocessing, creating menu items, setting up event handlers etc or performing cleanup upon exiting.

Dawid
  • 786
  • 3
  • 8
0

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: although I thought of using this approach and have used it in Excel, I didn't until I first encountered it on the PPT Alchemy web site: Run Code When PowerPoint Opens.

Jon Peltier
  • 5,895
  • 1
  • 27
  • 27