简体   繁体   English

PowerPoint VBA:如何将每张幻灯片单独保存为新演示文稿?

[英]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.我正在处理一个巨大的 Powerpoint 文件,该文件似乎太大了。 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.旧版本的 Powerpoint 使用不再可用的发布功能来解决问题。 So I tried to create this myself using a VBA macro, even though I'm fairly new to VBA.所以我尝试使用 VBA 宏自己创建它,即使我对 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.使用此宏时,PowerPoint 会保存所有幻灯片的文件,但它们都包含不止一张幻灯片。 Where is the mistake in this code?这段代码的错误在哪里?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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