Hello Excel Gurus!
I have an inspection worksheet where I use checkboxes, text and select images from the computer that get pasted in specific cells. I have created a "Clear Checklist" button that is coded to clear all checkboxes, text and images; however, the images are not getting deleted. The other items I want cleared work fine, just not the pictures. My code follows and I appreciate any help provided. Thank you.
Sub ClearCellsTypeC()
Dim ws As Worksheet
Dim c As Object
Dim shp As Shape
Dim shpA As Object
Dim originalCell As Range
Set ws = ThisWorkbook.Sheets("TYPE C")
Set originalCell = ws.Range("E1")
Range("B16:B26").ClearContents
Dim tb As OLEObject
For Each tb In ActiveSheet.OLEObjects
If TypeName(tb.Object) = "TextBox" Then
tb.Object = " "
End If
Next tb
For Each c In ActiveSheet.OLEObjects
If InStr(1, c.Name, "CheckBox") > 0 Then
c.Object.Value = False
End If
Next c
For Each shp In ws.Shapes
If shp.Type = msoPicture Then
shp.Delete
End If
Next shp
For Each shpA In ws.OLEObjects
If TypeName(shpA.Object) = "Picture" Then
shpA.Delete
End If
Next shpA
'Return to the original cell
originalCell.Select
End Sub
I have an inspection worksheet where I use checkboxes, text and select images from the computer that get pasted in specific cells. I have created a "Clear Checklist" button that is coded to clear all checkboxes, text and images; however, the images are not getting deleted. The other items I want cleared work fine, just not the pictures. My code follows and I appreciate any help provided. Thank you.
Sub ClearCellsTypeC()
Dim ws As Worksheet
Dim c As Object
Dim shp As Shape
Dim shpA As Object
Dim originalCell As Range
Set ws = ThisWorkbook.Sheets("TYPE C")
Set originalCell = ws.Range("E1")
Range("B16:B26").ClearContents
Dim tb As OLEObject
For Each tb In ActiveSheet.OLEObjects
If TypeName(tb.Object) = "TextBox" Then
tb.Object = " "
End If
Next tb
For Each c In ActiveSheet.OLEObjects
If InStr(1, c.Name, "CheckBox") > 0 Then
c.Object.Value = False
End If
Next c
For Each shp In ws.Shapes
If shp.Type = msoPicture Then
shp.Delete
End If
Next shp
For Each shpA In ws.OLEObjects
If TypeName(shpA.Object) = "Picture" Then
shpA.Delete
End If
Next shpA
'Return to the original cell
originalCell.Select
End Sub