从Excel中的Powerpoint幻灯片中删除图片 [英] delete pictures from slides in powerpoint from excel
问题描述
我试图弄清楚为什么编码不起作用,但是下面的代码应该从excel的powerpoint打开,并清除现有幻灯片以替换新图片-但是我得到了以下信息:>
I tried to figured out why the coding is not working, but the following code was supposed to open from excel a powerpoint and clear the existing slides in order to replace with new picture - however I'm getting the following:
错误91:未设置对象变量或块变量.
error 91: Object variable or with block variable not set.
我尝试了Stack中的其他几个代码,但无法使其正常工作..请问有什么帮助吗?甲板包含幻灯片2到幻灯片9以清除.
I tried several others code from the Stack but cannot make it work.. any help please? The deck contains slide 2 to slide 9 to cleared out.
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工作表作为图片复制到相应的幻灯片中来继续进行编码.
I'd like to know how to correct the code in order to continue the coding with copying excel worksheets as pictures into the respective slide.
推荐答案
首先,最重要的是,将Option Explicit
添加到代码模块的顶部,它将标记各种未声明的变量具有:p
,i
,ppSlide
和ppShape
.
First and most importantly, add Option Explicit
to the top of the code module, and it will flag the various undeclared variables you have: p
, i
, ppSlide
, and ppShape
.
然后代码可能看起来像这样:
Then the code might look something like this:
Option Explicit
Sub ExportToPPT()
Dim ppApp As PowerPoint.Application
Set ppApp = New PowerPoint.Application
Dim ppFileName As String
ppFileName = "C:\Users\\Desktop\Summary.pptx"
Dim ppPres As PowerPoint.Presentation
Set ppPres = ppApp.Presentations.Open(Filename:=ppFileName)
Dim ppSlide As PowerPoint.Slide
Dim i As Integer
For i = 2 To 9
Set ppSlide = ppPres.Slides(i)
Dim j As Integer
For j = ppSlide.Shapes.Count To 1 Step -1
If ppSlide.Shapes(j).Type = msoPicture Then
ppSlide.Shapes(j).Delete
End If
Next j
Next i
End Sub
这篇关于从Excel中的Powerpoint幻灯片中删除图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!