Sub DeleteImages()
Dim i As Long
Dim SourceWidth As Single
Dim SourceHeight As Single
Dim DeleteCounter As Long
' Check if a picture is selected
If Selection.InlineShapes.Count > 0 Then
' Save the dimensions of the source image
SourceWidth = Selection.InlineShapes(1).Width
SourceHeight = Selection.InlineShapes(1).Height
Else
MsgBox "No image selected"
Exit Sub
End If
' Initialize DeleteCounter
DeleteCounter = 0
' Loop backwards through all images in the document
For i = ActiveDocument.InlineShapes.Count To 1 Step -1
' Compare the images
If SourceWidth = ActiveDocument.InlineShapes(i).Width And SourceHeight = ActiveDocument.InlineShapes(i).Height Then
' Images are the same size, delete the target image and increment DeleteCounter
ActiveDocument.InlineShapes(i).Delete
DeleteCounter = DeleteCounter + 1
End If
Next i
' Output the number of deleted images
MsgBox "Number of deleted images: " & DeleteCounter
End Sub