Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 376
Kyle Uithoven Avatar asked Apr 27 '12 20:04

Kyle Uithoven


2 Answers

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.

like image 180
Steve Rindsberg Avatar answered Oct 12 '22 13:10

Steve Rindsberg


Answering to an old question, but I hope my solution might helpt 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.

like image 32
C. Binair Avatar answered Oct 12 '22 15:10

C. Binair