【问题标题】:Unable to open PowerPoint File using VBA无法使用 VBA 打开 PowerPoint 文件
【发布时间】:2017-11-18 12:18:41
【问题描述】:

我喜欢从 Excel 打开一个 PowerPoint 文件。 试了好几次都不行。

问题听起来与这些类似:

not able to Open Powerpoint using VBA

唯一的区别是,我得到另一个错误代码:

'Laufzeitfehler'-2147024894 (80070002)': Die Methode 'Open' für das Objekt 'Presentations' ist fehlgeschlagen.

我检查了 Microsoft PowerPoint 16.0 对象库是否已激活。我检查了几次文件路径。

有人知道错误是什么吗?

Sub sub_powerpoint_test()
Dim ObjPPT As PowerPoint.Application
Dim ObjPresentation As PowerPoint.Presentation
Dim str_FileName_PPTX As String

Set ObjPPT = CreateObject("PowerPoint.Application")
ObjPPT.Visible = msoCTrue


'Get PPT Filename
If Len(Dir(ThisWorkbook.Path & "\*.pptx")) = 0 Then
   MsgBox "PPTX file does NOT exist in this folder."
Else
     str_FileName_PPTX = ThisWorkbook.Path & Dir(ThisWorkbook.Path & "\*.pptx")
     Debug.Print str_FileName_PPTX
 End If


Set ObjPresentation = ObjPPT.Presentations.Open(str_FileName_PPTX, Untitled:=msoTrue)

End Sub

错误出现在最后的 Open 行中。

【问题讨论】:

    标签: vba excel powerpoint


    【解决方案1】:

    我找到了解决方案。问题是路径中缺少“\”。

    更正后的代码是:

    If Len(Dir(ThisWorkbook.Path & "\*.pptx")) = 0 Then
       MsgBox "PPTX file does NOT exist in this folder."
    Else
        str_FileName_PPTX = ThisWorkbook.Path & "\" & Dir(ThisWorkbook.Path & "\*.pptx")
        Debug.Print str_FileName_PPTX
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 2017-07-26
      • 2015-07-20
      • 1970-01-01
      • 2020-11-04
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多