Code to Remove Form Control buttons Q

S

Seanie

I have the code below which removes Form Control buttons, but it also
removes Charts I have on the sheet, how can I adjust the code below,
which will allow me to still remove the buttons but not the Charts?


Sub ClearMacroButtons()

On Error Resume Next
Sheets("Report").Select
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete
On Error GoTo 0
End Sub
 
D

Dave Peterson

If the buttons are from the Forms toolbar, you could use:

Dim BTN as button
for each btn in worksheets("report").buttons
btn.delete
next btn


If the commandbuttons are from the Control toolbox toolbar, you could use:

Dim OLEObj As OLEObject
For Each OLEObj In Worksheets("report").OLEObjects
If TypeOf OLEObj.Object Is MSForms.commandbutton Then
OLEObj.Delete
End If
Next OLEObj
 
S

Seanie

Thanks works like a dream, but how do I tweak to work through several
sheet? My existing code is

Sub ClearMacroButtons()

On Error Resume Next
Sheets(Array("E-Mail1", "E-Mail2", "E-Mail3", "E-Mail4", "E-
Mail5")).Select
ActiveSheet.DrawingObjects.Visible = True
ActiveSheet.DrawingObjects.Delete

On Error GoTo 0
End Sub

I tried, but it debugs

Sub ClearMacroButtons()
Dim BTN as button
for each btn in Sheets(Array("E-Mail1", "E-Mail2", "E-Mail3", "E-
Mail4", "E-Mail5")).buttons
btn.delete
next btn
End Sub
 
D

Dave Peterson

Option Explicit
Sub ClearMacroButtons()
Dim WksNames As Variant
Dim BTN As Button
Dim wCtr As Long

WksNames = Array("E-Mail1", "E-Mail2", "E-Mail3", "E-Mail4", "E-Mail5")

For wCtr = LBound(WksNames) To UBound(WksNames)
For Each BTN In Worksheets(WksNames(wCtr)).Buttons
BTN.Delete
Next BTN
Next wCtr

End Sub
 

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