vbapowerpointpowerpoint-2013

How not to count page numbers for hidden slides in PPT?


In presentation mode, I want only unhidden slides to appear with consecutive page numbers. How can I avoid that hidden slides are counted?


Solution

  • Thank you Steve. I found an answer to my question elsewhere. The function below allows you to avoid that hidden slides are interfering with the slide numbers of unhidden slides in presentation mode.

    Sub Number_NonHidden()
    'For v.2007 onwards only
    Dim osld As Slide
    Dim objSN As Shape
    Dim lngNum As Long
    'check all slides
    For Each osld In ActivePresentation.Slides
    'Is it hidden
    If osld.SlideShowTransition.Hidden Then
    osld.HeadersFooters.SlideNumber.Visible = False
    Else
    osld.HeadersFooters.SlideNumber.Visible = True
    Set objSN = getNumber(osld)
    lngNum = lngNum + 1
    If Not objSN Is Nothing Then ' there is a number placeholder
    objSN.TextFrame.TextRange = CStr(lngNum + 1)
    End If
    End If
    Next osld
    End Sub
    
    Function getNumber(thisSlide As Slide) As Shape
    For Each getNumber In thisSlide.Shapes
    If getNumber.Type = msoPlaceholder Then
    If getNumber.PlaceholderFormat.Type = ppPlaceholderSlideNumber Then
    'it's the slide number
    Exit Function
    End If
    End If
    Next getNumber
    End Function
    

    In order to avoid that the title slide is numbered insert lngNum = -1 as follows and delete the slide number box in the master title slide.

    'check all slides
    lngNum = -1
    For Each osld In ActivePresentation.Slides