首页 > 解决方案 > 从 Excel VBA 打开 PowerPoint

问题描述

所以,几天前我提出了一个关于 Excel 中 VBA 使用 PowerPoint 的问题,我已经取得了进展,但是我遇到了一个错误,我在这里没有找到答案。我希望有人能帮帮忙!

这是我的代码:

Sub ExportaraPowerPoint()

Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptShape As PowerPoint.Shape
Dim excelTable As Excel.Range
Dim Workbook As Excel.Workbook
Dim Worksheet As Excel.Worksheet
Dim i As Integer
Dim DestinationPPT As String

Set pptApp = CreateObject("PowerPoint.Application")
'I've also tried using Set pptApp = New PowerPoint.Application, but same result

Workbooks("def1.xlsm").Sheets("sheetname").Activate
'ActiveSheet.Range("B1:C35").Select
Set excelTable = ActiveSheet.Range("B57:L70")

DestinationPPT = "pathfile to definitive.pptm" 'NOTE: My ppt is Macro Enabled, maybe that creates a conflict? 
'I've double-checked it, by changing the file to pptx, but same error code

Set pptPres = pptApp.Presentations.Open(DestinationPPT) 'This is the line where I get the error

If pptApp Is Nothing Then MsgBox ("No se encuentra el archivo PowerPoint de destino")

pptApp.Visible = True
pptApp.Activate

Set pptSlide = ActivePresentation.Slides.Range("Slide name")

excelTable.Copy

pptSlide.Shapes.PasteSpecial(link:=True).Select
pptApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pptApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

End Sub

我得到的错误是(我必须从西班牙语翻译,所以它可能不是准确的翻译):

运行时错误 -2147024894 (80070002)。“演示文稿”对象的“打开”方法出错。

我已经解决了几天,但我没有找到任何解决方案。

感谢大家!

标签: excelvbaobjectpowerpoint

解决方案


推荐阅读