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



我正在处理一个巨大的Powerpoint文件,它似乎是一个太大的文件。为了找出哪些幻灯片导致文件变大并能够使其变小,我试图将每张幻灯片另存为一个单独的文件。

旧版本的Powerpoint使用不再可用的发布功能完成了这个技巧。所以我尝试使用 VBA 宏自己创建它,即使我对 VBA 相当陌生。请参阅下面的代码:

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") & "Desktopslides")
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") & "Desktopslidesslide" & L & ".pptx", EmbedTrueTypeFonts:=False)
tempPres.Slides(1).Delete
Next
tempPres.Close
End Sub

使用此宏时,PowerPoint 会保存所有幻灯片的文件,但它们都包含不止一张幻灯片。此代码中的错误在哪里?

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

最新更新