2017-11-18 5 views
0

ExcelからPowerPointファイルを開くのが好きです。 私は数回試しましたが、うまくいきません。VBAを使用してPowerPointファイルを開くことができません

問題は、これらに類似の音:

'Laufzeitfehler '-2147024894(80070002)': ダイMethodeの' オープン

が唯一の違いはある

not able to Open Powerpoint using VBA

が、私は別のエラーコードを取得します'fürdas Objekt'プレゼンテーション '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

解決策が見つかりました。問題は、パスに「\」がありませんでした。

修正されたコードは次のとおりです。

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 
関連する問題