Maximilian Kohl
Maximilian Kohl

Reputation: 640

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?

Upvotes: 11

Views: 23906

Answers (2)

Maximilian Kohl
Maximilian Kohl

Reputation: 640

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

Upvotes: 11

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

In VBA you'd do something like this:

Sub CountSlides()
Dim oSl As Slide
Dim x As Long
For Each oSl In ActivePresentation.Slides
    If Not oSl.SlideShowTransition.Hidden Then
        x = x + 1
    End If
Next
MsgBox x
End Sub

In other words, if the SlideShowTransition.Hidden property of the slide is True, don't count it.

Upvotes: 0

Related Questions