vbapowerpoint

Detecting Page Number TextBox in PowerPoint in VBA


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.


Solution

  • 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