VBA宏Excel打开PowerPoint:打开对象演示文稿的方法失败

时间:2018-09-05 17:35:39

标签: vba excel-vba powerpoint

我正在处理一个Excel文件,该文件涉及打开PowerPoint作为一个步骤。但是,当我运行它时,它会产生错误消息“对象演示文稿的方法打开失败”,当我单击“调试”时,它会突出显示“ Set myPresentation = PowerPointApp.Presentations.Open(“ DestinationPPT”)。请提供帮助。任何建议都是真诚的赞赏。

'Powerpoint
Sub OpenPowerPoint()

Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation

'Template Location variable
DestinationPPT = HOME.TextBox2.Value
DestinationPPT = DestinationPPT & "\Gemba Template.pptx"

Set PowerPointApp = CreateObject("PowerPoint.Application")
Set myPresentation = PowerPointApp.Presentations.Open("DestinationPPT")

'Transition from Excel to PowerPoint
Dim x, lastRow, slideNum As Integer
Dim cellName, shapeName, cellScore As String

enter image description here

1 个答案:

答案 0 :(得分:0)

假设您的HOME.Textbox.Value包含标准文件名,唯一的问题是您将早期对象绑定与后期对象绑定混合在一起。

'Powerpoint
Sub OpenPowerPoint()

Dim DestinationPPT As String
'You choose early binding, good choice
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation

'Template Location variable
DestinationPPT = HOME.TextBox2.Value
DestinationPPT = DestinationPPT & "\Gemba Template.pptx"

'The CreateObject function is for late binding of objects
'You choose early binding.  In that case use New.
'Set PowerPointApp = CreateObject("PowerPoint.Application")
Set PowerPointApp = New PowerPoint.Application
'Assuming HOME.Textbox.Value contains a fully qualified file string
'Remove the double quote marks since DestinationPPT is a vaiable not
'a literal
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

'Transition from Excel to PowerPoint
Dim x, lastRow, slideNum As Integer
Dim cellName, shapeName, cellScore As String