How to run the "OnEnterSlide" or "OnLeaveSlide" macro in Powerpoint VBA?

Is there any event that allows you to run a macro at any time when you enter a slide or leave a slide?

+7
vba powerpoint
source share
2 answers

SlideShowNextSlide or OnSlideShowPageChange

A complete list can be found at http://officeone.mvps.org/vba/events_version.html

Sample code from http://msdn.microsoft.com/en-us/library/aa211571%28office.11%29.aspx


This example determines the position of the slide for the slide following the SlideShowNextSlide Event.

If the next slide is slide three, the example will change the type of pointer to the pen and the color of the pen to red.

Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow) Dim Showpos As Integer Showpos = Wn.View.CurrentShowPosition + 1 If Showpos = 3 Then With ActivePresentation.SlideShowSettings.Run.View .PointerColor.RGB = RGB(255, 0, 0) .PointerType = ppSlideShowPointerPen End With Else With ActivePresentation.SlideShowSettings.Run.View .PointerColor.RGB = RGB(0, 0, 0) .PointerType = ppSlideShowPointerArrow End With End If End Sub 
+6
source share

I would like to add that this event really depends on the version of PowerPoint. For me (PP 2007), the following event works quite stably:

 Sub OnSlideShowPageChange(ByVal objWindow As SlideShowWindow) Debug.Print objWindow.View.Slide.SlideIndex ' you can use this to check which slide invokes the event End Sub 

This code does not need additional class structures (PPTEvent). But if you plan to use other events, it is recommended that you enable the initialization of this class in OnSlideShowPageChange.

Please note that this code copes with the first part of the given task - entering the slide. You may ask, "How about his departure?" Well, this is a matter of relativity. That which is included in one slide, at the same time goes to another. Just use objWindow.View.Slide.SlideIndex to track the current slide, compare it to the previous slide index and decide you just left it.

-2
source share

All Articles