I am trying to export PPT presentation to PDF format from Excel VBA. In code below, I constantly receive Type Mismatch error when attepmting to use ExportAsFixedFormat. Why? Please see the code below
Option Explicit
Private Const ppSaveAsPDF As Long = 2
Private Const ppSaveAsDefault As Long = 11
Private Const ppSaveAsPresentation As Long = 1
Private Const ppFixedFormatTypePDF As Long = 2
Private Const ppFixedFormatIntentPrint As Long = 2
Private Const msoTrue As Long = -1
Private Const ppPrintHandoutHorizontalFirst As Long = 2
Private Const ppPrintOutputType As Long = 2
Private Const ppPrintOutputFourSlideHandouts As Long = 8
Private Const ppPrintOutputTwoSlideHandouts As Long = 2
Sub My_PowerPointToPDF()
Dim oPowerPointApp As Object
Dim oPPT As Object
Dim sPowerPointSourceFileName As String
Dim sPowerPointDestFileName As String
sPowerPointSourceFileName = "C:\Users\xxx\Documents\PPTX 2 PDF Button.pptm"
sPowerPointDestFileName = "C:\Users\xxx\Documents\test.pdf"
On Error Resume Next 'Will error on GetObject if not already open
Set oPowerPointApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
If oPowerPointApp Is Nothing Then 'If Nothing then GetObject failed because PowerPoint not already open.
Set oPowerPointApp = CreateObject("PowerPoint.Application")
End If
oPowerPointApp.Visible = True
Set oPPT = oPowerPointApp.Presentations.Open(sPowerPointSourceFileName)
'Line below creates "Type mismatch" error. Why?
oPPT.ExportAsFixedFormat Path:=sPowerPointDestFileName, FixedFormatType:=ppFixedFormatTypePDF
oPPT.Close
oPowerPointApp.Quit
End Sub