Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-25
4
Medium Priority
?
5,348 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 1500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Setting the Scene Animations in PowerPoint are a great tool to convey messages when used carefuly with the content of your slides. There are plenty of animation effects and options, including a Repeat feature for individual animation effects. …
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 fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

670 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