Search code examples
vbapowerpointslideshow

VBA code not working in slideshow mode


I have this piece of code, it increases the value of a textbox in the current slide. Works fine in normal view, but for some reason in slideshow view, doesn't work at all, whats wrong with it?

Sub Label1Plus1()
Dim sld As Long

sld = ActiveWindow.Selection.SlideRange.SlideIndex
ActivePresentation.Slides(sld).Shapes("textbox1").TextFrame.TextRange.Text = ActivePresentation.Slides(sld).Shapes("textbox1").TextFrame.TextRange.Text + 1

End Sub

Solution

  • PPT won't show any error messages about errors in VBA code when you're in slide show view. That's why you're not seeing any errors, but if it did, you'd see an error when it hits:

    sld = ActiveWindow.Selection.SlideRange.SlideIndex
    

    You can't select anything in Slide Show view, so there can be no .Selection object.

    Instead use this:

    Dim Sld as Slide
    Set Sld = SlideShowWindows(1).View.Slide.Shapes("mytextbox")
    

    Or if you prefer to use Sld as a Long variable

    Sld = SlideShowWindows(1).View.Slide.SlideIndex