VBA – How to delete quickly all pictures from Excel?
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:
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:
Sub KillAllShapes(wks As Worksheet)
Dim sh As Shape
For Each sh In wks.Shapes
sh.Delete
Next
End Sub
So far so good!