从Excel VBA将PPT演示文稿导出为PDF

从Excel VBA将PPT演示文稿导出为PDF,vba,powerpoint,Vba,Powerpoint,我正在尝试将PPT演示文稿从Excel VBA导出为PDF格式。在下面的代码中,我在尝试使用ExportAsFixedFormat时经常收到类型不匹配错误。为什么?请参阅下面的代码 Option Explicit Private Const ppSaveAsPDF As Long = 2 Private Const ppSaveAsDefault As Long = 11 Private Const ppSaveAsPresentation As Long = 1 Private Const

我正在尝试将PPT演示文稿从Excel VBA导出为PDF格式。在下面的代码中,我在尝试使用ExportAsFixedFormat时经常收到类型不匹配错误。为什么?请参阅下面的代码

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

我不想在Excel VBA中手动添加对Microsoft PowerPoint库的引用,因为带有宏的文件将被邮寄给许多人。