Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
togglebutton to act like optionbutton
I have a worksheet with 5 toggle buttons. I need to get them to act like
option buttons where when one is clicked the other values will be set to false. I tried using the click event for each togglebutton to set the other toggles values to false, but as each one is set to false, the click event for that toggle runs. Any ideas how I can get this to work or is there a way to make option buttons look like toggle buttons? Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
togglebutton to act like optionbutton
Unfortunately it does not appear that you can suppress events from running
with the toggle buttons using Application.EnableEvents. However, I successfully got the following to work. I set a linked cell for each of the Toggle buttons so that I could observe their behaviour and it appears to work OK. Dim bolToggle As Boolean Private Sub ToggleButton1_Click() MsgBox "ToggleButton1_Click ran" & ToggleButton1.Value If ToggleButton1 = True Then bolToggle = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False End If bolToggle = True End Sub Private Sub ToggleButton2_Click() If bolToggle = True Then MsgBox "ToggleButton2_Click ran" & ToggleButton2.Value End If End Sub Private Sub ToggleButton3_Click() If bolToggle = True Then MsgBox "ToggleButton3_Click ran" & ToggleButton3.Value End If End Sub Private Sub ToggleButton4_Click() If bolToggle = True Then MsgBox "ToggleButton4_Click ran" & ToggleButton4.Value End If End Sub Private Sub ToggleButton5_Click() If bolToggle = True Then MsgBox "ToggleButton5_Click ran" & ToggleButton5.Value End If End Sub -- Regards, OssieMac "ranswrt" wrote: I have a worksheet with 5 toggle buttons. I need to get them to act like option buttons where when one is clicked the other values will be set to false. I tried using the click event for each togglebutton to set the other toggles values to false, but as each one is set to false, the click event for that toggle runs. Any ideas how I can get this to work or is there a way to make option buttons look like toggle buttons? Thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
togglebutton to act like optionbutton
Had another look at this and if my assumption is right that you only want
your code to run when the option button is true then I think that this is a simpler option. It changes all other options to false and you can put your code in after the code that changes the other option buttons:- Private Sub ToggleButton1_Click() If ToggleButton1 = True Then ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton2_Click() If ToggleButton2 = True Then ToggleButton1.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton3_Click() If ToggleButton3 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton4_Click() If ToggleButton4 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton5_Click() If ToggleButton5 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False 'Any other code here End If End Sub -- Regards, OssieMac "OssieMac" wrote: Unfortunately it does not appear that you can suppress events from running with the toggle buttons using Application.EnableEvents. However, I successfully got the following to work. I set a linked cell for each of the Toggle buttons so that I could observe their behaviour and it appears to work OK. Dim bolToggle As Boolean Private Sub ToggleButton1_Click() MsgBox "ToggleButton1_Click ran" & ToggleButton1.Value If ToggleButton1 = True Then bolToggle = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False End If bolToggle = True End Sub Private Sub ToggleButton2_Click() If bolToggle = True Then MsgBox "ToggleButton2_Click ran" & ToggleButton2.Value End If End Sub Private Sub ToggleButton3_Click() If bolToggle = True Then MsgBox "ToggleButton3_Click ran" & ToggleButton3.Value End If End Sub Private Sub ToggleButton4_Click() If bolToggle = True Then MsgBox "ToggleButton4_Click ran" & ToggleButton4.Value End If End Sub Private Sub ToggleButton5_Click() If bolToggle = True Then MsgBox "ToggleButton5_Click ran" & ToggleButton5.Value End If End Sub -- Regards, OssieMac "ranswrt" wrote: I have a worksheet with 5 toggle buttons. I need to get them to act like option buttons where when one is clicked the other values will be set to false. I tried using the click event for each togglebutton to set the other toggles values to false, but as each one is set to false, the click event for that toggle runs. Any ideas how I can get this to work or is there a way to make option buttons look like toggle buttons? Thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
togglebutton to act like optionbutton
I think that will work.
Thanks "OssieMac" wrote: Had another look at this and if my assumption is right that you only want your code to run when the option button is true then I think that this is a simpler option. It changes all other options to false and you can put your code in after the code that changes the other option buttons:- Private Sub ToggleButton1_Click() If ToggleButton1 = True Then ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton2_Click() If ToggleButton2 = True Then ToggleButton1.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton3_Click() If ToggleButton3 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton4.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton4_Click() If ToggleButton4 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton5.Value = False 'Any other code here End If End Sub Private Sub ToggleButton5_Click() If ToggleButton5 = True Then ToggleButton1.Value = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False 'Any other code here End If End Sub -- Regards, OssieMac "OssieMac" wrote: Unfortunately it does not appear that you can suppress events from running with the toggle buttons using Application.EnableEvents. However, I successfully got the following to work. I set a linked cell for each of the Toggle buttons so that I could observe their behaviour and it appears to work OK. Dim bolToggle As Boolean Private Sub ToggleButton1_Click() MsgBox "ToggleButton1_Click ran" & ToggleButton1.Value If ToggleButton1 = True Then bolToggle = False ToggleButton2.Value = False ToggleButton3.Value = False ToggleButton4.Value = False ToggleButton5.Value = False End If bolToggle = True End Sub Private Sub ToggleButton2_Click() If bolToggle = True Then MsgBox "ToggleButton2_Click ran" & ToggleButton2.Value End If End Sub Private Sub ToggleButton3_Click() If bolToggle = True Then MsgBox "ToggleButton3_Click ran" & ToggleButton3.Value End If End Sub Private Sub ToggleButton4_Click() If bolToggle = True Then MsgBox "ToggleButton4_Click ran" & ToggleButton4.Value End If End Sub Private Sub ToggleButton5_Click() If bolToggle = True Then MsgBox "ToggleButton5_Click ran" & ToggleButton5.Value End If End Sub -- Regards, OssieMac "ranswrt" wrote: I have a worksheet with 5 toggle buttons. I need to get them to act like option buttons where when one is clicked the other values will be set to false. I tried using the click event for each togglebutton to set the other toggles values to false, but as each one is set to false, the click event for that toggle runs. Any ideas how I can get this to work or is there a way to make option buttons look like toggle buttons? Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Togglebutton | Excel Programming | |||
Togglebutton | Excel Programming | |||
Setting ToggleButton Value | Excel Programming | |||
need help with togglebutton | Excel Programming | |||
2 macros in a Togglebutton? | Excel Programming |