ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete all commandbuttons in workbook (https://www.excelbanter.com/excel-programming/408354-delete-all-commandbuttons-workbook.html)

Steve[_4_]

Delete all commandbuttons in workbook
 
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

Ron de Bruin

Delete all commandbuttons in workbook
 
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


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Steve" wrote in message ...
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



All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com