【问题标题】:VBA Macros Excel Opening PowerPoint: method open of object presentations failedVBA宏Excel打开PowerPoint:对象演示的方法打开失败
【发布时间】:2018-09-05 17:35:39
【问题描述】:

我正在处理一个包含打开 PowerPoint 的 Excel 文件。但是,当我运行它时,它会产生错误消息“对象演示的方法打开失败”当我单击调试时,它会突出显示“设置 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

【问题讨论】:

  • "DestinationPPT" 中删除引号 - 它是一个变量,而不是字符串文字。
  • 那没用 :(
  • 确保DestinationPPT 是有效路径。否则,它将失败。测试debug.print DestinationPPT,看看结果如何
  • 结果给出了我桌面上文件夹/项目的有效路径
  • 您是否对路径有效性进行了三次检查?您可以复制/粘贴到 Windows 资源管理器并打开文件吗?因为:Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT) 将使用有效路径。

标签: vba excel powerpoint


【解决方案1】:

假设您的 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

【讨论】:

    猜你喜欢
    • 2023-02-24
    • 2013-12-15
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 2019-01-07
    • 2012-07-03
    相关资源
    最近更新 更多