Probably, if you are programming with Excel as much as me, one day you have the following question – all the pictures in Excel are generated by my code and I really do not care to give them names. I simply want to delete them all. Concerning the fact that you do not name the generated pictures, it is a little difficult to do it, naming each picture.
Anyway this query has a solution in the following code:
1 2 3 4 5 |
Sub KillPictures() For Each Shape In ActiveSheet.Shapes If Left(Shape.Name, 7) = "Picture" Then Shape.Delete Next End Sub |
It is quite a clever way to delete the pictures, eh? With a little modification, this can actually delete any shape you would like to. Simply change “Picture” to the name of the shape and change the “7” in the code to the number of the letters.
Simply to delete all the Shapes, then this is quite ok:
1 2 3 4 5 6 7 8 |
Sub KillAllShapes(wks As Worksheet) Dim sh As Shape For Each sh In wks.Shapes sh.Delete Next End Sub |
So far so good!