Release all buttons except the clicked ? How ?

bufos

New Member
Joined
Nov 14, 2015
Messages
4
Hi all,
I am using Excel Professional 2010
I have 12 buttons in a form with names like btn_Hos_... , I would like to make a method so as when I click on a button to disable the buttonand release all the others (in case which there is preesed button)

So, maybe I have to pass the name of the button to the method and release all the buttons except the parameter

Could you help me please how can I do this ?

Thanks in advance
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Perhaps something along these lines?

Code:
Private Sub SwitchButtons(btn As ToggleButton)
  Dim ctl As Control
  For Each ctl In Me.Controls
    If TypeOf ctl Is ToggleButton Then
      If ctl Is btn Then
        ctl.Enabled = False
      Else
        ctl.Enabled = True
        ctl.Value = False
      End If
    End If
  Next ctl
End Sub


Private Sub ToggleButton1_Click()
  If ToggleButton1.Value Then Call SwitchButtons(ToggleButton1)
End Sub


Private Sub ToggleButton2_Click()
  If ToggleButton2.Value Then Call SwitchButtons(ToggleButton2)
End Sub


Private Sub ToggleButton3_Click()
  If ToggleButton3.Value Then Call SwitchButtons(ToggleButton3)
End Sub


Private Sub ToggleButton4_Click()
  If ToggleButton4.Value Then Call SwitchButtons(ToggleButton4)
End Sub


Private Sub ToggleButton5_Click()
  If ToggleButton5.Value Then Call SwitchButtons(ToggleButton5)
End Sub

...
 
Last edited:
Upvote 0
Thanks a lot
I made something the following and I think that it works.

Code:
Private Sub ReleaseButtonsExceptClicked(ByRef cmdb As Object)
  Dim contr As Control
  
  ' loop through all control in user form
  For Each contr In Userform1.Controls
    ' check if control is type Command button
    If TypeName(contr) = "CommandButton" And contr.Name Like "btn_*" Then
        If contr.Name = cmdb.Name Then
            contr.Enabled = False
        Else
            contr.Enabled = True
        End If

    End If
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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