How do I remove all buttons in VBA on a sheet?

rpaolilloML

New Member
Joined
Dec 1, 2006
Messages
7
I am trying to write a macro that will remove all form Buttons. Any help is apreciated.

Regards,
Rob
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

this code allows you to restrict
1. the range (which you can enlarge to "cells" or usedrange)
2. the type of controls to delete
Code:
Sub delete_controls_within_range()

Dim sh As Shape
Dim rng As Range

Set rng = Range("A1:D10")

    For Each sh In ActiveSheet.Shapes
      If sh.Type = msoFormControl Then
        If sh.FormControlType = xlButtonControl _
        And Not Intersect(sh.TopLeftCell, rng) Is Nothing Then sh.Delete
      End If
    Next sh
End Sub
more documented
Code:
Sub delete_controls_within_range()
'Erik Van Geit
'050517 0053
'msoOLEControlObjects
'''CheckBox
'''TextBox
'''CommandButton
'''OptionButton
'''ListBox
'''ComboBox
'''ToggleButton
'''SpinButton
'''ScrollBar
'''Label
'''Image

'msoFormControl
'''xlButtonControl
'''xlCheckBox
'''xlDropDown
'''xlEditBox
'''xlGroupBox
'''xlLabel
'''xlListBox
'''xlOptionButton
'''xlScrollBar
'''xlSpinner

Dim sh As Shape
Dim rng As Range

Set rng = Range("A1:D10")

    For Each sh In ActiveSheet.Shapes
      If sh.Type = msoOLEControlObject Then
        If TypeName(sh.OLEFormat.Object.Object) = "ComboBox" _
        And Not Intersect(sh.TopLeftCell, rng) Is Nothing Then sh.Delete
      End If
      If sh.Type = msoFormControl Then
        If sh.FormControlType = xlCheckBox _
        And Not Intersect(sh.TopLeftCell, rng) Is Nothing Then sh.Delete
      End If
    Next sh
End Sub
replace "combobox" and xlcheckbox with the appropriate terms from the list on top
quote out half of the "for each" part if necessary (If sh.Type .... End If)

kind regards
Erik
 
Upvote 0

Forum statistics

Threads
1,225,132
Messages
6,183,039
Members
453,146
Latest member
scarabeovini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top