试图从活动的 ppt 幻灯片中删除表格

Trying to delete tables from active ppt slide

我正在尝试从 ppt 演示文稿的活动幻灯片中删除表格,但只有指定幻灯片的编号才能使其正常工作。我希望它适用于任何活动的幻灯片,而不是特定的幻灯片。下面的代码设置为从幻灯片 3 中删除表格。

Sub CopytoPPT()

    Dim rng As Excel.Range
    Dim sl As PowerPoint.Slide, sl_cnt As Long, pr As Object, pr_name As String, ppt As Object
        Dim i As Long, j As Long
    Set ppt = GetObject(, "PowerPoint.Application")
        Set pr = ppt.Presentations(1)

    Set sl = pr.Slides(3)
    For i = sl.Shapes.Count To 1 Step -1
    ' ADD THIS TEST
    If IsTable(sl.Shapes(i)) Then
      sl.Shapes(i).Delete
    End If
    Next i
    End Sub
    
    Function IsTable(oSh As Variant) As Boolean
        
        If oSh.Type = msoPlaceholder Then
            If oSh.PlaceholderFormat.ContainedType = msoTable Then
                IsTable = True
            End If
        Else
            If oSh.HasTable Then
                IsTable = True
            End If
            End If
    End Function

变化:

Set sl = pr.Slides(3)

收件人:

Set sl = ppt.ActiveWindow.View.Slide