Alex Brown
Alex Brown

Reputation: 33

Save PowerPoint pptm to pptx

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.

Upvotes: 3

Views: 13953

Answers (1)

Cor_Blimey
Cor_Blimey

Reputation: 3310

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

Upvotes: 4

Related Questions