Last active
November 23, 2024 18:21
-
-
Save ViniciusFM/138a9660d630d0490d02eae735d4dd10 to your computer and use it in GitHub Desktop.
This is a macro for slide counting on powerpoint. This macro only counts the slides that contain a Slide Number Shape on its surface. Everytime you execute this macro, each Slide Number Shape will receive a value like "N/T" where N is the # of the slide and T is the total # of slides containing the shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function GetSlideNumberShape(Sld As Slide) As Shape | |
' return a shape if a slide number shape exists in sld and nothing otherwise | |
Dim shp As Shape | |
For Each shp In Sld.Shapes | |
If InStr(1, shp.Name, "Slide Number", vbTextCompare) > 0 Then | |
Set GetSlideNumberShape = shp | |
End If | |
Next shp | |
End Function | |
Function GetTotalNumberOfSlideNumberShapes() As Integer | |
' get total number of slides that have slide number shapes | |
Dim Sld As Slide | |
Dim ret As Integer | |
ret = 0 | |
For Each Sld In ActivePresentation.Slides | |
If Not GetSlideNumberShape(Sld) Is Nothing Then | |
ret = ret + 1 | |
End If | |
Next Sld | |
GetTotalNumberOfSlideNumberShapes = ret | |
End Function | |
Sub UpdateSlideNumberShapes() | |
' only counts and updates slides that contain slide number shapes | |
Dim Sld As Slide | |
Dim shp As Shape | |
Dim slideIndex As Integer | |
Dim totalSlides As Integer | |
totalSlides = GetTotalNumberOfSlideNumberShapes() | |
slideIndex = 1 | |
For Each Sld In ActivePresentation.Slides | |
Set shp = GetSlideNumberShape(Sld) | |
If Not shp Is Nothing Then | |
shp.TextFrame.TextRange.Text = slideIndex & "/" & totalSlides | |
slideIndex = slideIndex + 1 | |
End If | |
Set shp = Nothing | |
Next Sld | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment