我找到了一段代码,可以将除事件幻灯片(索引 1)之外的所有 ppt 幻灯片一一删除。但是,任何人都可以帮助我重新编写此代码以一键执行代码。我不想循环播放每张幻灯片,因为要删除大约 300 张幻灯片。这是我的代码:

Sub Deleteslides()

'This deletes all slides except Active Main one.

Dim Pre As Presentation
Set Pre = ActivePresentation
Dim x As Long
For x = Pre.Slides.Count To 2 Step -1
    Pre.Slides(x).delete
Next x

End Sub

最佳答案

Sub Deleteslides()

    Dim Pre As Presentation, arr(), x As Long, n As Long
    Set Pre = ActivePresentation
    ReDim arr(0 To Pre.Slides.Count - 2)
    n = 0
    For x = Pre.Slides.Count To 2 Step -1
        arr(n) = x
        n = n + 1
    Next x
    Pre.Slides.Range(arr).Delete

End Sub

关于VBA 一次性删除所有幻灯片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38863450/

10-10 20:36