【发布时间】:2019-03-29 21:51:40
【问题描述】:
我试图弄清楚为什么编码不起作用,但以下代码应该从 excel 打开一个 powerpoint 并清除现有幻灯片以替换为新图片 - 但是我得到以下内容:
错误 91:未设置对象变量或块变量。
我尝试了堆栈中的其他几个代码,但无法使其正常工作.. 有什么帮助吗?甲板包含幻灯片 2 到幻灯片 9 以清除。
Sub ppt_export()
Dim DestinationPPT As String
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim objApp As Object, objSlide As Object, ObjShp As Object, objTable As` Object
DestinationPPT = "C:\Users\\Desktop\Summary.pptx"
Set ppApp = CreateObject("PowerPoint.Application")
Set ppPres = ppApp.Presentations.Open(DestinationPPT)
'delete the shapes from the renew the template
For i = ppSlide.Shapes.Count To 1 Step -1
Set ppShape = ppSlide.Shapes(p)
If ppShape.Type = msoPicture Then ppShape.Delete
Next
End Sub
我想知道如何更正代码,以便通过将 excel 工作表作为图片复制到相应幻灯片中来继续编码。
【问题讨论】:
-
将
Option Explicit添加到模块顶部,这会使您的问题变得明显。For语句使用i,但随后您尝试在循环内使用p。 -
@BigBen 谢谢,我将
p切换为i,但它循环到同样的错误。
标签: excel vba powerpoint