0
votes

I am working on a huge Powerpoint file which seems to be a file too big. In order to figure out which slides cause the big size of the file and to be able to make it smaller, I was trying to save each slide as an individual file.

Older versions of Powerpoint did the trick using the Publish function which isn't available any more. So I tried to create this myself using a VBA macro, even though I'm fairly new to VBA. Please see the code below:

Sub slidesizes()

    Dim L As Long
    Dim originPres As Presentation
    Dim tempPres As Presentation

    Set originPres = ActivePresentation
    originPres.SaveCopyAs (Environ("TEMP") & "\temppres.pptx")

    On Error Resume Next
    MkDir (Environ("USERPROFILE") & "\Desktop\slides\")
    Set tempPres = Presentations.Open(FileName:=Environ("TEMP") & "\temppres.pptx", WithWindow:=False)
    For L = originPres.Slides.Count To 1 Step -1
        originPres.Slides(L).Copy
        tempPres.Slides.Paste
        Call tempPres.SaveAs(FileName:=Environ("USERPROFILE") & "\Desktop\slides\slide" & L & ".pptx", EmbedTrueTypeFonts:=False)
        tempPres.Slides(1).Delete
    Next
    tempPres.Close
End Sub

When using this macro, powerpoint saves files for all slides, but they all contain more than just one slide. Where is the mistake in this code?

1

1 Answers

2
votes

Your tempPres contains more than one slide... Try to delete all but one slide before you go into your For L Loop.