使用Excel和VBA从PowerPoint文件生成PDF文件

时间:2019-03-14 08:17:56

标签: excel vba powerpoint

我正在尝试从PowerPoint文件生成PDF文件。所有这些都可以通过单击带有VBA脚本的Excel文件中的按钮来完成。到目前为止,我已经设法编写了以下代码。它会正确打开PowerPoint文件,但还会显示错误:“对象不支持此属性或方法”。

strPath = "Q:\X\Test.pptx"

Set objApp = CreateObject("Powerpoint.Application")
objApp.Visible = True 'False or True

Set wbToRun = objApp.Presentations.Open(strPath)

wbToRun.ExportAsFixedFormat  "<Q:\X\1.pdf>", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoCTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputBuildSlides, msoFalse, , , ,  False,  False,  False,  False,  False

objApp.DisplayAlerts = False
wbToRun.Close
objApp.Quit

希望您能够为我做错事提供帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

我能够重现您的错误。以下解决方案为我工作。确保已启用对Microsoft Powerpoint对象库的引用。

Sub ppttest5()

Dim savePath As String
Dim AppPowerPoint
Dim wbToRun

Set AppPowerPoint = CreateObject("PowerPoint.Application")
 'Location of saved file
savePathFN = "C:\mydirb\test.pdf" 'change as per your path
AppPowerPoint.Visible = True

Set wbToRun = AppPowerPoint.Presentations.Open("C:\mydirb\Test.pptx") 'change location of file path

wbToRun.SaveAs savePathFN, ppSaveAsPDF
wbToRun.Close


AppPowerPoint.Quit
Set OpenPresentation = Nothing
Set AppPowerPoint = Nothing

End Sub