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
Bookmarks