Solved

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

Posted on 2007-03-25
4
4,978 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
PowerPoint is the go-to presentation software for millions of users around the world. Many presentations use basic text features but you can really make special text jump out of your slide by applying this bubble text design process. This article ha…
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

856 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