我想删除PowerPoint演示文稿中的所有内容,但已存在的图表除外。我一直在寻找没有结果的日子。
但是我确实找到了删除所有图表的VBA。不幸的是,这与我要实现的目标相反。我尝试使用在其他代码中找到的VBA并将其添加,但是没有任何帮助。任何帮助将不胜感激。
Sub RemoveAllCharts()
Dim sld As Slide
Dim i, num
'Loop Through Each Slide in ActivePresentation
For Each sld In ActivePresentation.Slides
num = sld.Shapes.Count
For i = num To 1 Step -1
If sld.Shapes(i).HasChart Then
sld.Shapes(i).Delete
End If
Next i
Next sld
End Sub
答案 0 :(得分:2)
您也许可以添加Not
来实现此目的,即更改
If sld.Shapes(i).HasChart Then
到
If Not sld.Shapes(i).HasChart Then
Sub RemoveAllButCharts()
Dim sld As Slide
Dim i As Long, num As Long
'Loop Through Each Slide in ActivePresentation
For Each sld In ActivePresentation.Slides
num = sld.Shapes.Count
For i = num To 1 Step -1
If Not sld.Shapes(i).HasChart Then
sld.Shapes(i).Delete
End If
Next i
Next sld
End Sub