PowerPoint VBA:如何将每张幻灯片单独保存为新的演示文稿?
PowerPoint VBA: How to save each slide individually as new presentations?
我正在处理一个巨大的 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") & "\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
使用此宏时,powerpoint 会保存所有幻灯片的文件,但它们都包含不止一张幻灯片。这段代码哪里错了?
您的 tempPres 包含不止一张幻灯片...尝试在进入 For L 循环之前删除除一张幻灯片以外的所有幻灯片。
我正在处理一个巨大的 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") & "\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
使用此宏时,powerpoint 会保存所有幻灯片的文件,但它们都包含不止一张幻灯片。这段代码哪里错了?
您的 tempPres 包含不止一张幻灯片...尝试在进入 For L 循环之前删除除一张幻灯片以外的所有幻灯片。