1

I am trying to make a macro to update the page count of visible pages.

I have a code like this:

Sub SetVisiblePageNumers()
    Dim pageNumber As Integer
    Dim pp As String
    
    pageNumber = 1
    For Each page In Application.ActivePresentation.Slides
        If (page.SlideShowTransition.Hidden = False) Then
            For Each found In page.Shapes
               If found.**IsAPageNumberTextBox** Then
                    found.TextFrame.TextRange = CStr(pageNumber)
                 ' pp = found.TextFrame.Comment
                End If
            Next
       pageNumber = pageNumber + 1
       End If
 
    Next
End Sub

The field IsAPageNumberTextBox does not exist. But I am trying to find a way of knowing the text box is a page number. The text ‹#› is converted to page number. However I do not see how I can find this text as it would be a way of knowing that my text box is for the number.

4
  • 1
    if you haven't renamed the shapes then you can search for found.Name Like "Slide Number Placeholder*" Commented Jul 29 at 12:14
  • @Ike that's probably the only solution, just keep in mind that it is language dependent (in my Powerpoint it is called Tijdelijke aanduiding voor dianummer) Commented Jul 29 at 12:39
  • @Paul: I'm working with a German version ... the shape itself on the GUI is named "Foliennummernplatzhalter 2" - but within VBA shapes name is "Slide Number Placeholder 2". Commented Jul 29 at 12:53
  • If the page number is in the same place then you can find the shape based on its position on the slide? Commented Jul 29 at 16:07

1 Answer 1

2

This assumes that the page number is in its original placeholder shape.:

Sub SetVisiblePageNumers()
    Dim pageNumber As Integer
    Dim pp As String
    Dim oShape As shape
    
    pageNumber = 1
    For Each Page In Application.ActivePresentation.Slides
        If (Page.SlideShowTransition.Hidden = False) Then
            For Each oShape In Page.Shapes
                If oShape.Type = msoPlaceholder Then
                    If oShape.PlaceholderFormat.Type = ppPlaceholderSlideNumber Then
                        oShape.TextFrame.textRange = CStr(pageNumber)
                    End If
                End If
            Next
       pageNumber = pageNumber + 1
       End If
    Next
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

This solution seems to work. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.