从Excel VBA中将PPT演示文稿导出为PDF [英] Exporting PPT presentation to PDF from Excel VBA

查看:46
本文介绍了从Excel VBA中将PPT演示文稿导出为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将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:UsersxxxDocumentsPPTX 2 PDF Button.pptm"
sPowerPointDestFileName = "C:UsersxxxDocuments	est.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

推荐答案

这似乎是ExportAsFixedFormat的PowerPoint文档中的错误或错误。PrintRange不是可选的。您可以通过添加PrintRange:=Nothing的参数来修复错误。

我遇到了同样的问题,此答案提示我找到了解决方案:https://stackoverflow.com/a/32995017/3541707

这篇关于从Excel VBA中将PPT演示文稿导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆