我试图用VBA删除PowerPoint形状上的所有幻灯片。我想做的只是:
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
sh.Delete
Next
Next
但这并没有删除所有形状,如下图所示:(灰色箭头是我在运行下面的代码之前添加的形状,但也不会消失)
对我做错了什么的想法?
答案 0 :(得分:2)
这真的很有趣,我能够重新创造问题。我还首先尝试计数并迭代计数;然而,问题是有多少形状在那里刷新实时。我的意思是如果它将一个时间点的形状计为2个形状,那么当删除形状时,那里只有1个形状。因此,最好的办法是循环删除每次删除第一个形状的形状计数。
For Each sld In ActivePresentation.Slides
TotalShapes = sld.Shapes.Count
For i = TotalShapes to 1 step -1
sld.Shapes(i).Delete
Next
Next
谢谢, 肖恩W。
答案 1 :(得分:1)
或者你可以说:
sld.Shapes.Range.Delete
答案 2 :(得分:1)
typo: missing 0 in > 0
While ActivePresentation.Slides.Count > 0
While ActivePresentation.Slides(1).Shapes.Count **> 0**
ActivePresentation.Slides(1).Shapes(1).Delete
Wend
ActivePresentation.Slides(1).Delete
Wend
答案 3 :(得分:0)
For Each sld In ActivePresentation.Slides
For x = sld.shapes.count to 1 step -1
sld.shapes(x).Delete
Next
Next
答案 4 :(得分:0)
我认为,最简单的方法是:
while ActivePresentation.Slides.count>0
while ActivePresentation.Slides(1).shapes.count>
ActivePresentation.Slides(1).shapes(1).delete
wend
ActivePresentation.Slides(1).delete
wend