Deleting pictures with Excel VBA

北战南征 提交于 2019-12-19 16:52:37

问题


How do I delete all the pictures in an Excel 2007 worksheet? A working code example would be great.


回答1:


Dim shape As Excel.shape

For Each shape In ActiveSheet.Shapes
        shape.Delete
Next



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4480231/deleting-pictures-with-excel-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!