Solved

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

Posted on 2007-03-25
4
5,039 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Suggested Solutions

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…
Setting the Scene PowerPoint is a creative tool in the right hands but it also includes a much underutilised programming dimension. In this beginner level article, we're going to show you some of some key elements of programming PowerPoint using th…
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.

735 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