我想从Excel打开一个PowerPoint文件。 我已经尝试了好几次但它不起作用。
问题听起来与这些相似:
not able to Open Powerpoint using VBA
唯一的区别是,我得到另一个错误代码:
'Laufzeitfehler'-2147024894(80070002)': DieMethode'Open'fürdasObjekt'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
最后在打开行中发生错误。
答案 0 :(得分: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