Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA delete all slides in one go

Tags:

vba

I have found a piece of code to delete all ppt slides one by one except the the Active one (Index 1). However, can any one help me in re-writing this code to action the code in one hit. I don't want to loop each and every slide as there will be about 300 slides to delete. This is the code I have:

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
like image 839
Camille Avatar asked Jan 21 '26 19:01

Camille


1 Answers

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
like image 59
Tim Williams Avatar answered Jan 23 '26 19:01

Tim Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!