MS PowerPoint 15.0对象库

时间:2018-01-30 16:09:20

标签: vba excel-vba excel-2013 powerpoint-vba powerpoint-2013

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

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

  

方法&#39>打开'对象'演示文稿'失败

PPT 15.0对象库中是否弃用了Presentations.Open方法?我尝试搜索互联网,但无法找到有关变更的文档。

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

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

非常感谢您的帮助。

早期绑定代码Snipnet

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

后期绑定代码Snipnet

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

0 个答案:

没有答案