Delete all pictures. Not ComboBOX

Carlos260488

New Member
Joined
Aug 22, 2014
Messages
8
How can I delete all pictures in active sheet without deleting my ComboBox.

I've already tried:

Code:
Sub DeletePcsTest001()
ActiveSheet.Pictures.Delete
End Sub

and

Code:
Sub DeletePcsTest0002()
ActiveSheet.Shapes.SelectAll
Selection.Delete
End Sub

both of those delete my combo box

Should I create an If function to avoid macro killing my combo box??
or is there any property in combo box to lock it?

Thanks in advance!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
For a Picture:

Code:
Sub PicKiller()
    Dim s As Shape
    For Each s In ActiveSheet.Shapes
        If s.Type = 13 Then
            s.Delete
        End If
    Next s
End Sub

You would use a different code for an AutoShape, etc.
 
Upvote 0
Hi! Its working fine with pictures... now, I don't know why With my picture is not working... Has it something to do with my picture being a 'file001.PNG' instead of a 'file002.JPG'. 'cause I notice with '*.JPG' file is working perfectly fine.

Thanks!
 
Upvote 0
I don't know.......on my system Excel 2007 / Win 7 it works on .JPG and .PNG and .GIF

But we can run a test:

Code:
Sub hfskjdfh()
Dim s As Shape
For Each s In ActiveSheet.Shapes
    MsgBox s.Name & vbCrLf & s.Type
Next s
End Sub
 
Upvote 0
It is not working yet :(

Is there some way we can add an 'If' step so that it will clear everything that is named " picture * "

This macro is to create a label. When they select a part number from combo box, the picture is suppoused to insert a specific picture related to this part number. Final step of this Macro is avoiding fill the screen/file with a lot of pictures one over the other once they have selected different part numbers a couple of times.

Thank you again for your help.
 
Upvote 0
Here is what you requested:

Code:
Sub PicKiller()
    Dim s As Shape
    For Each s In ActiveSheet.Shapes
        n = LCase(s.Name)
        If InStr(1, n, "picture") > 0 Then
            s.Delete
        End If
    Next s
End Sub
 
Upvote 0
Here is what you requested:

Code:
Sub PicKiller()
    Dim s As Shape
    For Each s In ActiveSheet.Shapes
        n = LCase(s.Name)
        If InStr(1, n, "picture") > 0 Then
            s.Delete
        End If
    Next s
End Sub

Hello!

but you code depends on objects name. If you'll edit your object name it'll not work

Below code detects and deletes all objects besides Form and ActiveX Controls

Code:
Sub Remove_Objects()
For Each shp In ActiveSheet.Shapes
If shp.Type <> 12 And shp.Type <> 8 Then
shp.Delete
End If
Next
End Sub
 
Upvote 0
You're right! It's just that i didn't know what kind of shape type ComboBox was... Yet it's working.


Now I'm going to paste both and use the first one in certain situations and the other one in others haha...


Have a good one!:biggrin:
 
Upvote 0
You're right! It's just that i didn't know what kind of shape type ComboBox was... Yet it's working.


Now I'm going to paste both and use the first one in certain situations and the other one in others haha...


Have a good one!:biggrin:


Glad for you! :)
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top