Do you need to convert your ppt files to pdf? This post explains how to convert the PPT files in a folder to PDF using Excel VBA.
Suppose you have developed automation that generates the number of PowerPoint files and stores them in a folder. It will be good practice that instead of sharing PowerPoint files, you can convert the same as a pdf and share it with your colleagues.
How to convert PPT to PDF
VBA Script
Sub pptTOpdf()
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim onlyFileName As String, folderPath As String, pptFile As String, removeFileExt As Long
Dim sFldr As String
Application.ScreenUpdating = False
' Open the folder dialog box to select
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select folder"
If .Show = -1 Then
sFldr = .SelectedItems(1)
End If
End With
If sFldr = "" Then ' if user did not select folder
MsgBox "You did not select the folder, Macro exits"
End If
'Assign values
folderPath = sFldr & "\"
pptFile = Dir(folderPath & "*.pp*")
'If no ppt files are in the selected folder exit sub
If pptFile = "" Then
MsgBox "No files found"
Exit Sub
End If
Do While pptFile <> ""
'Assign the PPT application
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
On Error Resume Next
'Assign the PPT presentation
Set oPPTFile = oPPTApp.Presentations.Open(folderPath & pptFile)
On Error GoTo 0
'Assign only file name to variable removeFileExt = InStr(1, oPPTFile.Name, ".") - 1
onlyFileName = Left(oPPTFile.Name, removeFileExt)
'Save as PDF
oPPTFile.ExportAsFixedFormat oPPTFile.Path & "\" & onlyFileName & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint
'Close Powerpoint file
oPPTFile.Close
'loop for the next file
pptFile = Dir()
Loop
'close Powerpoint Application
oPPTApp.Quit
'Release memory
Set oPPTFile = Nothing
Set oPPTApp = Nothing
Application.ScreenUpdating = True
MsgBox " Succesfully converted"
End Sub
Copy and paste the above VBA script to your VBE Module
How to run VBA in Excel
Please follow the below steps to run the above code
- Select anywhere in your script in your VBE module
- Press Green Arrow to execute the Macro or press F5
- The macro pop up a success message once it is executed
- Press OK
You can see the macro-generated PDF files in the same folder along with the PowerPoint files.
Conclusions
Your user can open the pdf files through either adobe or a browser window. if you share your report as a PowerPoint file, The user has to install the application and view the PowerPoint slides.