vba 将 PowerPoint pptm 保存为 pptx
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18289234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Save PowerPoint pptm to pptx
提问by Alex Brown
I am making my first steps in VBA. I have been trying many things, but still I haven't figured out a way to save a .pptm powerpoint presentation to .pptx format with the same file name in a specific path? I already use the following code to save as pdf.
我正在 VBA 中迈出第一步。我一直在尝试很多东西,但我仍然没有想出一种方法来将 .pptm PowerPoint 演示文稿保存为 .pptx 格式,并在特定路径中使用相同的文件名?我已经使用以下代码保存为 pdf。
ActivePresentation.ExportAsFixedFormat "c:\" + Replace(ActivePresentation.Name, "pptm", "pdf"), ppFixedFormatTypePDF, ppFixedFormatIntentPrint, msoCTrue
ActivePresentation.ExportAsFixedFormat "c:\" + Replace(ActivePresentation.Name, "pptm", "pdf"), ppFixedFormatTypePDF, ppFixedFormatIntentPrint, msoCTrue
Thank you in advance.
先感谢您。
回答by Cor_Blimey
Basic usage is:
基本用法是:
With ActivePresentation
.SaveCopyAs _
FileName:=.Path & "\" & Left(.Name, InStrRev(.Name, ".")) & "pptx", _
FileFormat:=ppSaveAsOpenXMLPresentation
End With
(Or you can use .SaveAs. SaveAsCopy keeps the current open and doesn't open the copy, whereas .SaveAs sets the current to be the saved version)
(或者您可以使用 .SaveAs。SaveAsCopy 保持当前打开状态并且不打开副本,而 .SaveAs 将当前设置为保存的版本)
However, if the Powerpoint you are saving hasn't been saved at least once then the above will error (there is no file extension in Presentation.Name to find with InStrRev). You can either test for there being no full stop, or you can use a lazy method of asking FileSystemObject to get you the name without an extension (I am lazy so I prefer this method):
但是,如果您保存的 Powerpoint 至少没有保存过一次,则上述内容会出错(Presentation.Name 中没有文件扩展名可以使用 InStrRev 查找)。您可以测试没有句号,也可以使用懒惰的方法要求 FileSystemObject 获取没有扩展名的名称(我很懒,所以我更喜欢这种方法):
So a better more robust method is:
所以更好更健壮的方法是:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
With ActivePresentation
.SaveCopyAs _
FileName:=fso.BuildPath(.Path, fso.GetBaseName(.Name) & ".pptx"), _
FileFormat:=ppSaveAsOpenXMLPresentation
End With