Deleting pictures with Excel VBA
How do I delete all the pictures in an Excel 2开发者_如何学Python007 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.
Dim shape As Excel.shape
For Each shape In ActiveSheet.Shapes
shape.Delete
Next
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
精彩评论