选择一个图形,执行此代码后,所有幻灯片上和此图形位置、大小相同的图形都会被删除。
代码如下:
Sub 批量删除()
Dim oSlide As Slide, oShape As Shape
Dim myWidth As Single, myHeight As Single, myTop As Single, myLeft As Single
On Error Resume Next
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then
If Err.Number <> 0 Then
MsgBox "未选择任何对象。" & vbCrLf & "请先选择1个图形。", vbExclamation + vbOKOnly
Err.Clear
Exit Sub
End If
MsgBox "未选择图形或选择的图形超过1个。" & vbCrLf & "请先选择1个图形。", vbExclamation + vbOKOnly
Exit Sub
End If
Set oShape = ActiveWindow.Selection.ShapeRange(1)
myTop = oShape.Top
myLeft = oShape.Left
myHeight = oShape.Height
myWidth = oShape.Width
For Each oSlide In ActivePresentation.Slides
For Each oShape In oSlide.Shapes
'有时候图形会有一点移动或变形,所以采用了近似的算法来包容此情况'
If Abs(myTop - oShape.Top) < 1 And Abs(myLeft - oShape.Left) < 1 And Abs(myHeight - oShape.Height) < 1 And Abs(myWidth - oShape.Width) < 1 Then
oShape.Delete
End If
Next
Next
End Sub
暂无评论,我来发表第一篇评论!
发表评论