Results 1 to 13 of 13

VBA to convert multiple PowerPoint files into one pdf

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    VBA to convert multiple PowerPoint files into one pdf

    Hello,

    From an excel workbook, I want to select a folder (with filepath referenced in cell k3) containing approx 20 PowerPoint presentations and export their content into a pdf file with the same name as the original but with the new .pdf suffix. I found some vba online which I have tried to adapt but it gives an error on the line which is removing the file extensions. Please would someone be willing to take a look and advise?

    This is the line which is currently giving the error but I don�t know if this is the only problem;

    removeFileExt = InStr(1, oPPTFile.Name, ".") - 1
    Thank you,

    Jess

    Sub ppt2pdf()
    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("k3").Text & "\"
    'pptFiles = Dir(folderpath & "*.pp*") (Original)
    pptFiles = (folderpath & "*.pp*")
     
    'check for ppt files and exit if not found
    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
    oPPTApp.Quit
    Set oPPTFile = Nothing
    Set oPPTApp = Nothing
     
    Application.ScreenUpdating = True
     
    End Sub
    Last edited by Brontosaurus; 01-15-2025 at 08:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to print multiple Powerpoint files using Macro
    By greenarrow in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-31-2017, 11:08 AM
  2. convert multiple pptx files into mp4 videos using powerpoint vba
    By shiva_raj in forum PowerPoint Formatting & General
    Replies: 3
    Last Post: 04-03-2017, 02:25 AM
  3. Windows 7 :Need to convert PDF files to PowerPoint,Any suggestion?
    By hourer in forum Microsoft Windows Help
    Replies: 6
    Last Post: 03-11-2016, 06:30 AM
  4. [SOLVED] Convert all Powerpoint files into PDF from an Excel VBA
    By benishiryo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2016, 10:25 AM
  5. Convert Multiple text files to excel files
    By shanmugapriya.a in forum Excel General
    Replies: 3
    Last Post: 07-07-2015, 10:39 AM
  6. Convert multiple text files to be excel files
    By PStump in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2014, 05:44 PM
  7. [SOLVED] how to convert multiple .txt files to .xlsx files using a macro?
    By Aaron_Tram in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2013, 06:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1