ribbon 2007, radio button

amigos.pl

New Member
Joined
Jul 2, 2009
Messages
31
Hi there, since there are no radio buttons in 2007 I want to use 2
toggleButtons and use them so one excludes the other one...

I am after the same functionality as you can see in View\Workbook Views\
but I have no idea how this is done

I tried 2 toggleButton in one group, one box and I also tried a separator...didn't work


Can anyone tell me how this is done?


Or (even better) anyone can tell me how to find XML which Excel uses for it's default ribbon?


Thanks in advance


Bartek
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Ah, there are radio buttons (or Option Buttons as Excel calls them), they're just very well hidden!

To access them, you need to have the Developer tab visible (which for some bizarre reason - presumably because most users don't need to need to have anything to do with macros or form controls - Excel chooses not to display by default)

1) Click the Office button in top left corner of screen
2) At bottom of dialog, select Excel Options
3) On the Popular sheet tick the box Show Developer Tab on Ribbon (third item down)
4) Click OK to close Options
5) Click the Developer tab on the ribbon
6) Click the Insert icon in the Control group.

You can now add either Forms Controls or ActiveX controls as needed.
 
Last edited:
Upvote 0
custom ribbon with 2 togglebuttons.
Add getPressed, OnAction and LoadRibbon call backs.

In a standard code module in the workbook add the following code.

Code:
Public g_rbxUI As IRibbonUI
Public g_blnToggleA As Boolean
Public g_blnToggleB As Boolean
Public Sub Togglebutton1_onAction(control As IRibbonControl, ByRef cancelDefault)
'
' Code for onAction callback. Ribbon control toggleButton
'
    g_blnToggleA = True
    g_blnToggleB = False
    g_rbxUI.InvalidateControl "Togglebutton1"
    g_rbxUI.InvalidateControl "Togglebutton2"
    
End Sub
Public Sub Togglebutton2_onAction(control As IRibbonControl, ByRef cancelDefault)
'
' Code for onAction callback. Ribbon control toggleButton
'
    g_blnToggleA = False
    g_blnToggleB = True
    g_rbxUI.InvalidateControl "Togglebutton1"
    g_rbxUI.InvalidateControl "Togglebutton2"
    
End Sub

Public Sub Togglebutton1_getPressed(control As IRibbonControl, ByRef returnedVal)
'
' Code for getPressed callback. Ribbon control toggleButton
'
    If control.ID = "Togglebutton1" Then
        returnedVal = g_blnToggleA
    ElseIf control.ID = "Togglebutton2" Then
        returnedVal = g_blnToggleB
    End If
    
End Sub
Public Sub rbxUI_******(ribbon As IRibbonUI)
'
' Code for ****** callback. Ribbon control customUI
'
    Set g_rbxUI = ribbon
End Sub
 
Upvote 0
Here is a crude radio button example using the getImage approach.

2 Buttons with OnAction and getImage callbacks. And ****** callback for ribbon.

Code in standard code module within workbook.

Code:
Public g_rbxUI As IRibbonUI
Public g_blnOpt(1 To 2) As Boolean
Public Sub Button1_getImage(control As IRibbonControl, ByRef returnedVal)
'
' Code for getImage callback. Ribbon control button
'
    If g_blnOpt(1) Then
        returnedVal = "ActiveXRadioButton"
    Else
        returnedVal = "ShapeDonut"
    End If

End Sub
Public Sub Button2_getImage(control As IRibbonControl, ByRef returnedVal)
'
' Code for getImage callback. Ribbon control button
'
    If g_blnOpt(2) Then
        returnedVal = "ActiveXRadioButton"
    Else
        returnedVal = "ShapeDonut"
    End If
End Sub
Public Sub Button1_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
    g_blnOpt(1) = True
    g_blnOpt(2) = False
    g_rbxUI.InvalidateControl "Button1"
    g_rbxUI.InvalidateControl "Button2"
End Sub
Public Sub Button2_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
    g_blnOpt(1) = False
    g_blnOpt(2) = True
    g_rbxUI.InvalidateControl "Button1"
    g_rbxUI.InvalidateControl "Button2"

End Sub
Public Sub rbxUI_******(ribbon As IRibbonUI)
'
' Code for ****** callback. Ribbon control customUI
'
    Set g_rbxUI = ribbon
End Sub
 
Upvote 0
Thank you Andy, that works perfectly

I can't believe it has to be handled on VBA level isntead of having grouped buttons in XML....Microsoft.

cheers

Bartek
 
Upvote 0
Hi:

I have a problem with this line of code in the macro:

g_rbxUI.InvalidateControl "Togglebutton1"


I get this error---> Runtime Error 91: Object variable or With block variable not set

What may be the reason? I´m using the exact same code as the example from Andy Pope

Kind Regards,

Hugo
 
Upvote 0
It means your ribbon variable has been reset.
 
Upvote 0

Forum statistics

Threads
1,215,362
Messages
6,124,502
Members
449,166
Latest member
hokjock

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