简体   繁体   中英

PowerPoint VBA: How to save each slide individually as new presentations?

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?

您的 tempPres 包含多张幻灯片...在进入 For L 循环之前尝试删除除一张幻灯片之外的所有幻灯片。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM