Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to have a simple macro run whenever I enter a new slide, whether I got there by normal click-to-advance or by following a link within the slideshow. Is this possible? I've searched for some kind of "page" or "slide" object upon which I could add an "enter" or "load" action, but if it exists I have not found it yet.

The goal is to set a "previous slide" global var, which is used to implement a Back button. Note that this button returns the user to the last slide he or she was on, not necessarily the previous slide in order. That is, on slide #4 I click a link to slide #101 in the appendix, then click Back and I go back to #4, not #100. This works fine, I just need to know which slide I was at.

As a workaround, I'm adding an invisible object to the slide master, with a mouse-over action to call this macro. This should work, but it seems ugly.

Is there a better way? Thank you!


Here's the code which worked:

 Public PreviousSlideIndex As Long
 Public CurrentSlideIndex As Long

 Public Sub OnSlideShowPageChange(ByVal Window As SlideShowWindow)
      PreviousSlideIndex = CurrentSlideIndex
      CurrentSlideIndex = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
 End Sub

 Sub ReturnToPreviousSlide()
      ActivePresentation.SlideShowWindow.View.GoToSlide PreviousSlideIndex
 End Sub

I set ReturnToPreviousSlide to the OnClick action for my Back button, and all's good.

You could make this a little sophisticated with a stack of previous pages, allowing users to futz around for a few slides and still return from whence they came.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I believe you're looking for the SlideShowNextSlide event, as documented at http://msdn.microsoft.com/en-us/library/ff745863.aspx:

Occurs immediately before the transition to the next slide. For the first slide, occurs immediately after the SlideShowBegin event.

An example is included at the MSDN link.

Per http://officeone.mvps.org/vba/run_macro_at_slide.html ("Run VBA macro at a particular slide"), there is also a OnSlideShowPageChange event, though I've not been able to find any official documentation for this on MDSN. However, per http://officeone.mvps.org/vba/events_version.html:

Occurs after showing the new slide.

This is an auto-macro and does not require any object to be declared. It is fired even when the presentation that hosts these event handlers is not in slide show mode.

share|improve this answer
    
The OnSlideShowPageChange event was perfect, with minimal overhead. Thanks! –  Jon of All Trades Dec 29 '11 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.