Skip to content

Instantly share code, notes, and snippets.

@CSalih
Created June 22, 2024 01:19
Show Gist options
  • Save CSalih/659629ea54c425ca39ad7812a1a6cfc5 to your computer and use it in GitHub Desktop.
Save CSalih/659629ea54c425ca39ad7812a1a6cfc5 to your computer and use it in GitHub Desktop.
Do not count page number for hidden slides in PPT
' Open VBA Editor with Alt + F11
' Insert > Module
' Pase code underneath and press F5 to run
' Source: https://stackoverflow.com/a/26469723
Sub Number_NonHidden()
'For v.2007 onwards only
Dim osld As Slide
Dim objSN As Shape
Dim lngNum As Long
'check all slides
lngNum = -2
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment