ribbon's togglebutton label not working

anziga

Board Regular
Joined
Feb 4, 2011
Messages
55
I set a new toggleButton to Excel ribbon:
<togglebutton
id="rxblockmacros"
getLabel="GetLabel"
size="large"
onAction="rxblockmacros_Click"
imageMso="AfterDelete"
screentip="Block / activate macros" />
Everything else works fine but not the label function.
Code:
Sub GetLabel(ByVal control As IRibbonControl, ByRef returnedVal)
       Select Case control.ID
        Case "rxblockmacros"
         If bLabelState Then
          returnedVal = "Activate macros"
         Else
          returnedVal = "Block macros"
        End If
      Case Else
     ' do nothing
     End Select
I have tried tons of various ways, but it just doesn't change the text of the toggleButton. When I open that particular document, button will get the label from this function, depending on how I have set bLabelState.
Code:
Option Explicit
Public grxIRibbonUI As IRibbonUI
Private bLabelState As Boolean
'Callback for customUI.******
Sub rxIRibbonUI_******(ribbon As IRibbonUI)
      Set grxIRibbonUI = ribbon
      bLabelState = True
End Sub
Any idea what I could try?
</togglebutton>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You need to invalidate the control when the toggle button is clicked.

Code:
Public Sub rxblockmacros_onAction(control As IRibbonControl, pressed As Boolean)
' Code for onAction callback. Ribbon control toggleButton
'
    bLabelState = Not bLabelState
    g_rbxUI.InvalidateControl "rxblockmacros"
    
End Sub
 
Upvote 0
Hi Andy

Thanks for the tip. For some reason I got an error message:
Run-time error '91': "Object variable or With block variable not set"

Debugger points to this row:
Code:
grxIRibbonUI.InvalidateControl "rxblockmacros"
 
Upvote 0
That means your Ribbon variable has gone out of scope. Usually caused by debugging or an unhandled error in your code.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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