Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Convert Multiple PowerPoint Files Into Pdf with Excel VBA?

  • Last Updated : 22 Dec, 2021

Often clients need PPT files as PDFs.  It helps to view on any device.  Use below VBA Macro to convert PowerPoint files from a folder and save them as PDF in tha same folder.

Implementation:

Follow the below steps to convert multiple PowerPoint files into PDFs using Excel VBA:

Step 1: Open Excel.

Step 2: Type text “Folder Path” in cell “B5” (Image 1).

Step 3: Enter your folder full path in cell “C5”  (Image 1). Here we have a folder “D:\Excel\29.ppt2pdf\ppt” with two PPT files (Image 2).

Image 1

Image 2

Step 4: Write below VBA code in your VBE module 

Sub ppt2pdf_Macro()
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim onlyFileName As String, folderPath As String, pptFiles As String, removeFileExt As Long
      
Application.ScreenUpdating = False
  • Initialize variables
folderPath = Range("C5").Text & "\"
pptFiles = Dir(folderPath & "*.pp*")
  • Check and exit macro if no ppt files are in the folder
If pptFiles = "" Then
    MsgBox "No files found"
    Exit Sub
End If

Do While pptFiles <> ""
  • Assign PowerPoint application to variable
    Set oPPTApp = CreateObject("PowerPoint.Application")
    oPPTApp.Visible = msoTrue
      
    On Error Resume Next
  • Assign PowerPoint presentation to variable
    Set oPPTFile = oPPTApp.Presentations.Open(folderPath & pptFiles)
        
    On Error GoTo 0
  • Remove file extension and assign an only file name to a variable
    removeFileExt = InStr(1, oPPTFile.Name, ".") - 1
    onlyFileName = Left(oPPTFile.Name, removeFileExt)
    
    On Error Resume Next
  • Save ppt file to pdf file
    oPPTFile.ExportAsFixedFormat oPPTFile.Path & "\" & onlyFileName & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint
    oPPTFile.Close
  • Iterate to the next file in the folder
    pptFiles = Dir()
Loop
  • Close PPT Application and release memory
oPPTApp.Quit

Set oPPTFile = Nothing
Set oPPTApp = Nothing
    
Application.ScreenUpdating = True

MsgBox " Successfully converted"
End Sub

Step 5: To Run VBA Code:  

  • Press “Alt + F8” – to popup Macro dialog box.
  • Select Macro “ppt2pdf_Macro” and click “RUN”.

Step 6: Macro convert all PPT files from the folder to PDF and popup a below message

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!