1

I like to open a PowerPoint file from Excel. I have tried it several times but it does not work.

The Problem sounds similar to these:

not able to Open Powerpoint using VBA

The only difference is, I get another error code:

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

I checked that the Microsoft PowerPoint 16.0 Object Library ist activated. And i checked the filepath several times.

Does anyone have an idea what the mistake can be?

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

The error occures in the Open line at the end.

1 Answer 1

2

I found the solution. The Problem was a missing "\" in the path.

The corrected code is:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.