Save PowerPoint pptm to pptx

╄→尐↘猪︶ㄣ 提交于 2019-12-20 01:47:21

问题


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.

ActivePresentation.ExportAsFixedFormat "c:\" + Replace(ActivePresentation.Name, "pptm", "pdf"), ppFixedFormatTypePDF, ppFixedFormatIntentPrint, msoCTrue

Thank you in advance.


回答1:


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)

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):

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


来源:https://stackoverflow.com/questions/18289234/save-powerpoint-pptm-to-pptx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!