excel - 从 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)。“演示文稿”对象的“打开”方法出错。
我已经解决了几天,但我没有找到任何解决方案。
感谢大家!
解决方案
推荐阅读
- angular - HttpClient 无法忽略或绕过自签名证书错误
- servicestack - ServiceStack:访问Service中的IRequest返回null
- python - 通过 SNR 检测 EEG 数据中的 Alpha 波?Python
- blender - 我在 Maya 和 Blender 中遇到枢轴问题
- html - 如何控制导航栏中的链接边距和填充?
- groovy - 在 Eclipse Groovy 程序中找不到类异常
- django - Django TestCase 类 - 为什么有些方法是骆驼案例而另一些是蛇案例?
- wordpress - 我想在 wp 主题中添加插件文件
- javascript - 键入脚本左右合并对象
- mysql - SQL查询 - 如何通过计数函数获得等于1的行