Search code examples
vbapowerpoint

How to check if there is table with only one row on PowerPoint presentation slide and how to delete the slide containing such table?


There is PowerPoint presentation. I need to search slides containig table that consists of one row and delete such slides. How to do it?

P.S. I'm sorry for such a stupid question, guys, but there is a project (about 50 000 lines) full of sh*tty code written not by me. The program generates presentations. I found about 3 reasons why such slide can appear in the presentations, and I fixed them all. Such slides still are in presentations, and I need to fix the problem fast(


Solution

  • Something like this:

    Sub DeleteOneRowTables()
    
    Dim oSh As Shape
    Dim x As Long
    Dim oSl As Slide
    
    For Each oSl In ActivePresentation.Slides
    
        For x = oSl.Shapes.Count To 1 Step -1
            With oSl.Shapes(x)
                If .HasTable Then
                    If .Table.Rows.Count = 1 Then
                        .Delete
                    End If  ' Rows count
                End If  ' has table
            End With
        Next    ' x
    
    Next    ' Slide
    
    End Sub