当我试图通过宏修改PowerPoint演示文稿时,Excel硬崩溃了



大家好,我想把我的工作报告系统自动化。为此,我设置了一个宏,在按下Excel中的按钮时,将:

  1. 在给定路径下从给定模板(.potx)打开一个新的演示文稿
  2. 添加各种图表
  3. 将新创建的演示文稿保存到另一个给定路径

因为这对我来说是很新的,我一步一步地移动,但我在开始时卡住了。这是我到目前为止的代码:


Dim PP As PowerPoint.Application
Dim report As PowerPoint.Presentation
Dim report_activeslide As PowerPoint.Slide
'Dim Slide_1_text As Shape
Dim path_template As String
Dim path_report As String

path_template = "path_template.potx"
path_report = "path_report"

Set PP = New PowerPoint.Application
Set report = PP.Presentations.Open(path_template, False, True, True)

PP.Visible = msoTrue

'Set report_activeslide = report.Slides(1)

report.SaveAs path_report, ppSaveAsOpenXMLPresentation, msoTrue

End Sub

到目前为止,我能够从模板中打开演示文稿并正确保存它。然而,当我真正开始对演示本身做任何事情的时候,比如把评论从'Set report_activeslide = report.Slides(1)行,Excel硬崩溃

有人知道问题在哪里吗?如果有什么不同的话,我在Mac上运行的是Office 365。

正如Ike在评论中指出的那样,代码可以在Windows上工作(我有机会自己测试它)。这让我意识到我的问题可能是由于Mac,而不是代码,事实证明,这是正确的。确实有不少人报告了同样的问题(例如:Excel VBA在引用PowerPoint幻灯片索引号时崩溃)

所以现在,在微软提供更好的OLE实现之前,我无法实际解决这个问题。

最新更新