0

我正在从 Excel 电子表格中调用 VBA 代码,以通过该Presentations.Open方法打开现有的 PowerPoint 文件。在我的环境中,我使用 MS PowerPoint 14.0 对象库通过 Early Binding 开发,并且代码运行没有问题。

但是,当在另一台运行 MS Office 2013(即 MS PowerPoint 15.0 对象库)的机器上调用脚本时,会弹出运行时错误

对象“演示文稿”的方法“打开”失败

PPT 15.0 对象库中是否已弃用 Presentations.Open 方法?我尝试搜索 Internet,但找不到有关更改的文档。

我还尝试使用后期绑定来查看它是否有效,但收到了同样的错误。

请在下面找到我使用的代码片段(早期 + 后期绑定)。

非常感谢你的帮助。


早期绑定代码片段

Sub EarlyBinding()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

Dim PowerpointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation

Set PowerpointApp = New PowerPoint.Application
PowerpointApp.Visible = True

Dim myPath As String
myPath = ws.Range("wk_dir").Value & "\" & ws.Range("ppt_name").Value

Set myPresentation = PowerpointApp.presentations.Open(myPath)
myPresentation.SaveAs (ws.Range("wk_dir").Value & "\test_earlybind.pptx")

Set myPresentation = Nothing
Set PowerpointApp = Nothing
End Sub

后期绑定代码片段

Sub LateBinding()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

Dim PowerpointApp As Object
Dim myPresentation As Object

Set PowerpointApp = CreateObject("Powerpoint.Application")
PowerpointApp.Visible = True

Dim myPath As String
myPath = ws.Range("wk_dir").Value & "\" & ws.Range("ppt_name").Value

Set myPresentation = PowerpointApp.presentations.Open(myPath)

myPresentation.SaveAs (ws.Range("wk_dir").Value & "\test_latebind.pptx")

Set myPresentation = Nothing
Set PowerpointApp = Nothing
End Sub
4

0 回答 0