Kyle Uithoven
Kyle Uithoven

Reputation: 2444

Powerpoint VBA App_SlideShowBegin

In order to use the SlideShowBegin event in Powerpoint, you have to have a Class Module configured the following way:

Public WithEvents App As Application

    Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
        MsgBox "SlideShowBegin"
    End Sub

Then, inside of a non-class module, you have to create an object of that type and set the App to Application.

Dim X As New Class1

Sub InitializeApp()
Set X.App = Application
End Sub

Now, the only issue I have is, if you don't manually called InitializeApp with the Macro Menu in Powerpoint, the events don't work. You have to call this sub before anything can called at the beginning of a slideshow INCLUDING this sub.

How can I go about calling this sub before running my powerpoint? Is there a better way to do this?

EDIT:

I've tried using Class_Initialize but it only gets called once it is first used or you make a statement like Dim X as Class1; X = new Class1

Upvotes: 6

Views: 7283

Answers (3)

C. Binair
C. Binair

Reputation: 451

Answering to an old question, but I hope my solution might help somebody ending up at this question.

The general advice for this issue is using a plug-in or placing some element on the slide and when that is clicked or hovered perform the initialization. Both are not always desired so I have the following approach:

In some module:

Dim slideShowRunning As Boolean
-----------------------------
Sub SlideShowBegin(ByVal Wn As SlideShowWindow)
    ' Your code for start-up
End Sub
-----------------------------
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
    If TypeName(slideShowRunning) = "Empty" Or slideShowRunning = False Then
        slideShowRunning = True
        SlideShowBegin Wn
    End If
End Sub
----------------------------
Public Sub OnSlideShowTerminate(ByVal Wn As SlideShowWindow)
    slideShowRunning = False
End Sub

For me this works perfectly. NOTE I am by no means a vba expert, actually I might have less than 50 hours of vba programming (maybe only 8 in powerpoint). So this might be an horrible solution. I don't know, but for me it works so I liked to share.

Upvotes: 1

Md. Jahurul Islam
Md. Jahurul Islam

Reputation: 51

In fact, OnSlideShowPageChange runs when slideshow begins. Just make sure it doesn't work in the subsequent page changes if not needed using a global variable. See answer from C. Binair for details.

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 3528

Usually event handlers are installed as part of an add-in, where you'd initialize the class in the Auto_Open subroutine, which always runs when the add-in loads. If you want to include an event handler in a single presentation, one way to cause it to init is to include a shape that, when moused over or clicked fires a macro, which inits your event handler and goes to the next slide.

Upvotes: 1

Related Questions