如果只需要匹配形状的大小和位置,则按需求删除下面代码中的 If 条件即可,即删除 shp.Type = selectedShp.Type _ 和 And shp.Name = selectedShp.Name _,并将 And shp.Left = selectedShp.Left _ 最前面的 And 删除。
Sub DeleteShapesBySelection()
Dim sld As Slide
Dim shp, selectedShp As Shape
Dim slideIndex As Long
Dim count, idx, shpCount As Long
If ActiveWindow.Selection.Type = ppSelectionShapes Or ActiveWindow.Selection.Type = ppSelectionText Then
' A shape is selected or a textbox is focused (text is selected)
count = 0
slideIndex = ActiveWindow.Selection.SlideRange.SlideIndex
For Each selectedShp In ActiveWindow.Selection.ShapeRange
For Each sld In ActivePresentation.Slides
If sld.SlideIndex <> slideIndex Then
shpCount = sld.Shapes.count
For idx = shpCount To 1 Step -1
Set shp = sld.Shapes(idx)
If ( _
shp.Type = selectedShp.Type _
And shp.Name = selectedShp.Name _
And shp.Left = selectedShp.Left _
And shp.Top = selectedShp.Top _
And shp.Width = selectedShp.Width _
And shp.Height = selectedShp.Height _
) Then
shp.Delete
count = count + 1
End If
Next idx
End If
Next sld
selectedShp.Delete
count = count + 1
Next selectedShp
MsgBox "共删除了" & count & "个形状。"
Else
MsgBox "未发现任何选中的形状或文本框", vbExclamation, "No Shape Found"
End If
End Sub