Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

A Next Slide button that runs code also

Problem

Sometimes you want to do something automatically when a user changes slides, or you need a way to force some macro code to run automatically when a user starts a slide show. Or you might need to initialize an event handler at the start of a slide show without having to resort to an add-in.

If you can write macro code to do the "something", you're halfway there. The trick is to force the code to run "automatically" when you start the presentation. Or at least to appear to.

PowerPoint won't run code from a presentation automatically, but you can start the presentation with an introductory slide. On it, you can place a "Start The Show" button. Give the button an action setting of Run Macro and have it run GoToNextSlide (code below). Modify GoToNextSlide to initialize your event handler.

Solution

Sub GoToNextSlide()
' Instead of a normal Next Slide action button
' have your Next Slide action = Run Macro and have it
' run this instead.
'
' This runs any additional code you like and then
' goes to the next slide

    ' add whatever code you like here or better yet,
    ' put it in a separate subroutine and call it from here
    ' for example:

    Call ExampleCode

    With ActivePresentation.SlideShowWindow
        .View.GotoSlide (ActivePresentation.SlideShowWindow.View.Slide.SlideIndex + 1)
    End With

    ' or add code here, after you've moved to the next slide
    Call ExampleCode

End Sub

Sub ExampleCode()
    MsgBox ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

A Next Slide button that runs code also
http://www.pptfaq.com/FAQ00954_A_Next_Slide_button_that_runs_code_also.htm
Last update 07 June, 2011
Created: