Trouble with toggleButtons on ribbon

X

xp

Hi, I have two custom toggle buttons on a ribbon and my code looks okay to
me, but obviously I've done something wrong because everytime I click either
one, I get "Object variable or with block variable not set" error; my code is
below, can someone PLEASE help me out with this?

Public gRibbonUI As IRibbonUI
Public gbPressed1 As Boolean
Public gbPressed2 As Boolean

'Callback for customUI.onLoad
Sub rxRibbonUI_onLoad(ribbon As IRibbonUI)
Set gRibbonUI = ribbon
End Sub

'Callback for rxTB1 getLabel
Sub BalAct_getLabel(control As IRibbonControl, ByRef returnedVal)
If gbPressed1 Then
returnedVal = "Activity"
ThisWorkbook.Worksheets(gcsSheetSET).Range("B14").FormulaR1C1 = "A"
Else
returnedVal = "Balance"
ThisWorkbook.Worksheets(gcsSheetSET).Range("B14").FormulaR1C1 = "B"
End If
End Sub

'Callback for rxTB1 onAction
Sub BalAct_Click(control As IRibbonControl, pressed As Boolean)
gbPressed1 = pressed
gRibbonUI.InvalidateControl ("rxTB1")
End Sub

'**********************************************************************************

'Callback for rxTB2 getLabel
Sub BudAct_getLabel(control As IRibbonControl, ByRef returnedVal)
If gbPressed2 Then
returnedVal = "Budget"
ThisWorkbook.Worksheets(gcsSheetSET).Range("B15").FormulaR1C1 = "B"
Else
returnedVal = "Actual"
ThisWorkbook.Worksheets(gcsSheetSET).Range("B14").FormulaR1C1 = "A"
End If
End Sub

'Callback for rxTB2 onAction
Sub BudAct_Click(control As IRibbonControl, pressed As Boolean)
gbPressed2 = pressed
gRibbonUI.InvalidateControl ("rxTB2")
End Sub
 
X

xp

I think I got it working; I think the problem was that I was sharing a
variable that should not have been shared. Once I declared a separate
variable (one for each of the two controls) it seems to be working...

I will continue to check back, however, in case someone has the time to
examine my code and offer further suggestions...thanks!
 

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