How do I delete all the pictures in an Excel 2007 worksheet? A working code example would be great.
The simplest way:
Activesheet.Pictures.Delete
or
Activesheet.Shapes.Delete
Depending on the type of object your picture is.
Deletes all pictures with greater efficiency then iterating (looping through) and deleting them one by one.
To delete all pictures or others shapes, you can iterate all of them and check the type:
Dim shape As Excel.shape
For Each shape In ActiveSheet.Shapes
Select Case shape.Type
Case msoPicture, msoMedia, msoShapeTypeMixed, msoOLEControlObject, msoAutoShape
shape.Delete
Case Else
'Do nothing
End Select
Next
In my case this code was usefull because my sheet was full of transparent shapes of type msoAutoShape which I thought were pictures. So, Activesheet.Pictures.Delete was not working.
You can find all shape types on this link: http://msdn.microsoft.com/en-us/library/aa432678(v=office.12).aspx
Dim shape As Excel.shape
For Each shape In ActiveSheet.Shapes
shape.Delete
Next