• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Deleting only images from worksheet using macro

skylar

New Member
Hi,

I want to delete multiple images from the worksheet using macro. I tried different codes but none of them are giving the desired result. Either they delete all the objects including combobox and buttons or they don't do anything (couldn't find msoPicture).

Macro which I tried:

Sub DeletePictures()
Dim shp As Shape
For Each shp In ActiveSheet.ShapeRange
If shp.Type = msoPicture Then
shp.Delete
End If
Next shp
End Sub

Sub DeleteImage()
Dim Pic As Object
For Each Pic In ActiveSheet.Pictures
Pic.Delete
Next Pic
End Sub

Any help would be appreciated.
 
Generally speaking when you add an image to an Excel sheet its default naming is like Picture 1/ Picture 2/ Picture 3 etc. So we can use the name of the shape to identify what to delete

Code:
Sub Pic_Delete()

Dim shp As Shape

For Each shp In ActiveSheet.Shapes
    If shp.Name Like "Picture*" Then
        shp.Delete
    Else
    End If
Next shp

End Sub
 
Thanks! It worked.
The only change which I made was replaced 'Picture' with 'Rectangle' as the image names were Rectangle*.
 
Back
Top