Deleting pictures with Excel VBA

后端 未结 3 1118
鱼传尺愫
鱼传尺愫 2021-01-17 13:46

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

相关标签:
3条回答
  • 2021-01-17 14:21

    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.

    0 讨论(0)
  • 2021-01-17 14:26

    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

    0 讨论(0)
  • 2021-01-17 14:28
    Dim shape As Excel.shape
    
    For Each shape In ActiveSheet.Shapes
            shape.Delete
    Next
    
    0 讨论(0)
提交回复
热议问题