PDA

View Full Version : Solved: delete all images from spreadsheet



crmpicco
05-17-2005, 05:09 AM
I am looking for code that will delete all images from spreadsheet.

Just do a search then delete any it finds.

TIA>

Picco

Bob Phillips
05-17-2005, 05:35 AM
Here is some code that will delete all shapes. The tricky thing here is that if you have any autofilter or data validations on the sheet, it deletes the arrows, and you can't get them back,

This is some code I picked up in the NGs that caters for that


Sub DeleteShapes()
'-------------------------------------------------------
' Author: Bob Phillips
' Additional test for topleft cell address
' to cater for forms combobox added by
' Dave Peterson
' Function: Delete all shapes from a worksheet
' Constraints: Don't delete autofilter and Data
' Validation arrows
'-------------------------------------------------------
Dim shp As Shape
Dim testStr As String
Dim OkToDelete As Boolean

For Each shp In ActiveSheet.Shapes
OkToDelete = True
testStr = ""
On Error Resume Next
testStr = shp.TopLeftCell.Address
On Error GoTo 0
If shp.Type = msoFormControl Then
If shp.FormControlType = xlDropDown Then
If testStr = "" Then
'keep it
OkToDelete = False
End If
End If
End If
If OkToDelete Then
shp.Delete
End If
Next shp

End Sub

crmpicco
05-17-2005, 06:38 AM
that works great - cheers

crmpicco
12-12-2005, 07:47 AM
has anyone got similar code that will remove any objects?

such as buttons and the like?:whistle:

Bob Phillips
12-12-2005, 11:17 AM
has anyone got similar code that will remove any objects?

such as buttons and the like?:whistle:

Doesn't my code do just that?