Solved

How to run VBA Code when a PowerPoint Presentation (ppt) opens?

Posted on 2007-03-25
4
4,832 Views
Last Modified: 2012-08-13
How can I automatically run some VBA Code when I open up a PowerPoint 2003 presentation (ppt)?
0
Comment
Question by:BobSue
  • 2
4 Comments
 
LVL 7

Expert Comment

by:hippohood
ID: 18791287
As I understand you wnat to use events AfterPresentationOpen or PresentationOpen, which happens after an existing presentation file is open.
Noi, you can't, sorry, not in a simple way like in Excel or Winword. To have the events working you have to initialize the Application object BEFORE the file is open. This kind of chicken-egg problem. What you can is to run the Initialize event from a previously open file or manually, or create and install an add-in with an Auto_open macro.
That means you need the user to prepare his Powerpoint to run your macro by installing and Add-in. Or, somehow, run an initialization macro (only once) beforehand each time when he opens Powerpoint. If this is ok for you, I (or someone else) can teach you how to do that.
Another option is that you open your file using a shortcut, in which you can put a command to run some script.
0
 

Author Comment

by:BobSue
ID: 18794736
Thanks hippohood!
I like the command line option with the add-in option second.
Any assistance in either of those areas would be great.

Have a great day!
Bob
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 18807349
As an alternative, you can use VB to initialize PowerPoint itself and totally control the whole presentation with VB.NET.

See: http://support.microsoft.com/kb/303717/en-us

Have a good one,
Glenna
www.pptmagic.com
0
 
LVL 7

Accepted Solution

by:
hippohood earned 500 total points
ID: 18815041
Sorry for delay. I was sure that someone can help you with add-ins.
Here is a code to create an add-ins.
1) Put the code in a new Module in VBA editor (Alt+F11).
2) compile it
3) save presentation  as PPA file
This add-in should be loaded on a machine where you want to use it.
4) From powerpoint Tools -> Add-Ins, "Add New", find and open that PPA file
To run the initialization macro press the new button on Toolbar. After that you can open your file with embedded event handler AfterPresentationOpen (see the MS help about that)

'===============
Dim X As New EventClassModule
Sub InitializeApp()
    Set X.App = Application
End Sub

Sub Auto_Open()
    Dim aToolbar As CommandBar
    Dim aButton As CommandBarButton

    Dim NewToolbarName$

    NewToolbarName  = "Initialize"

    Set aToolbar = CommandBars.Add(Name:=NewToolbarName , _
        Position:=msoBarFloating, Temporary:=True)
    If Err.Number <> 0 Then  
          ' The toolbar's already there, so we have nothing to do
          Exit Sub
    End If
    Set aButton = aToolbar.Controls.Add(Type:=msoControlButton)

    With aButton
         .DescriptionText = " Initialize "   
         .Caption = " Initialize!"    
         .OnAction = "InitializeApp"  
         .FaceId = 52      
    End With
End Sub
'==================================
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been sent a PowerPoint presentation file and wondered why it filled your mailbox? Or have you ever sent a PowerPoint presentation by email and received complaints about the size? Or have you ever created a PowerPoint presentation and t…
Introduction In all recent versions of PowerPoint it is possible to trigger animations. This means the animation takes place when a certain shape is clicked. This allows you to run animation “on demand” and outwith the normal sequence of mouse cl…
The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now