Delete all commandbuttons in workbook

S

Steve

Is there a way to delete all the commandbuttons in the entire
workbook? I found some code below that does it for a single sheet.
Thanks!

Sub DeleteCommandButtons()
Dim Obj As OLEObject
For Each Obj In ActiveSheet.OLEObjects
If Obj.progID = "Forms.CommandButton.1" Then
Obj.Delete
End If
Next Obj
End Sub
 
R

Ron de Bruin

Hi steve

Sub OLEObjects3()
'Delete/hide only all CommandButtons from the Control Toolbox
Dim obj As OLEObject
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
For Each obj In sh.OLEObjects
If TypeOf obj.Object Is MSForms.CommandButton Then
obj.Delete
' or obj.Visible = False if you want to hide them
End If
Next
Next sh
End Sub


See also
http://www.rondebruin.nl/controlsobjectsworksheet.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top