Consulting

Results 1 to 6 of 6

Thread: Deleting all images in a worksheet

  1. #1
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location

    Deleting all images in a worksheet

    Hi,

    I know how to delete one image that I see in a worksheet, but how can I manage to delete all images on a worksheet, knowing that I don't know how many there are and what their number are?

    Jungix

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to be careful

    Sub DeleteShapes()
    Dim oShape As Shape
    Dim sTest As String
    Dim OKToDelete As Boolean
    For Each oShape In ActiveSheet.Shapes
        OKToDelete = True
        sTest = ""
        On Error Resume Next
        sTest = oShape.TopLeftCell.Address
        On Error GoTo 0
        If oShape.Type = msoFormControl Then
            If oShape.FormControlType = xlDropDown Then
                If sTest = "" Then
                     'keep it
                     OKToDelete = False
                End If
            End If
        End If
        If OKToDelete Then
            oShape.Delete
        End If
    Next shp
    End Sub

  3. #3
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location
    Thanks, with Next oShape it worked on my sample.

    Why did you say I should be careful? What is your sTest doing?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by jungix
    Thanks, with Next oShape it worked on my sample.

    Why did you say I should be careful? What is your sTest doing?
    Because the easy way is to go


    For Each oShape In ActiveSheet.Shapes
        oShape.Delete
    Next oShape

    but the problem here is that it also removes the Data Validation dropdown and the Autofilter dropdown, and there is no way to get them back. I developed the convoluted method shown previously to avoid this.

  5. #5
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Quote Originally Posted by xld
    but the problem here is that it also removes the Data Validation dropdown and the Autofilter dropdown, and there is no way to get them back.


    That's a pretty significant issue!
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by matthewspatrick


    That's a pretty significant issue!
    Slight correction, you can re-create the autofilter which will restore that arrow, that's a pain but it can be done, but I know of no way to get the DV arrow back. The even worse part of that is that it is gone from the sheet, thaht is if you create a new List DV on that sheet, it too will not have an arrow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •