PC Review


Reply
Thread Tools Rate Thread

Delete all commandbuttons in workbook

 
 
Steve
Guest
Posts: n/a
 
      26th Mar 2008
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
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      26th Mar 2008
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" <(E-Mail Removed)> wrote in message news:e9d304af-e741-41c4-8a3a-(E-Mail Removed)...
> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy worksheet WITH CommandButtons within Workbook DonJ_Austin Microsoft Excel Programming 0 19th Feb 2009 05:47 PM
delete workbook from one location and save workbook to new locatio =?Utf-8?B?RGFtaWVu?= Microsoft Excel Programming 5 3rd Aug 2006 03:05 PM
How to Delete a Range in Closed Workbook (to Replace Delete Query) resant_v@yahoo.com Microsoft Excel Misc 1 8th Mar 2006 10:10 AM
re: Automatically Delete WorkBook 2 modules by using Workbook 1 module =?Utf-8?B?ZGRpaWNj?= Microsoft Excel Programming 5 27th Jul 2005 12:53 PM
delete commandbuttons on copied sheet qerj Microsoft Excel Programming 6 16th Feb 2004 01:18 PM


Features
 

Advertising
 

Newsgroups
 


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