Problem with IRibbonUI - Help please!


R

rick

I have a problem with my understanding of the IRibbonUI and it's driving me
crazy.

My XML is a Dictator (turns everything off except the QAT) and the I have 6
custom tabs each using the getVisible callback. In a Workflow module I
(would like to) control which tabs are hidden and which are visible as the
user proceeds from phase to phase. After playing with Mr. Schmid's examples
I determined that I needed to use invalidatecontrol rather than the whole
ribbon (invalidate). But my code doesn't run correctly.

I thought that using Invalidate would delete the whole cache and then
trigger the getVisible for all tabs/controls. And it does. I also thought
that Invaalidatecontrol would only delete the cache for the control and then
the getVisible for that control would fire. This is not the case. All
controls are returned to the getVisible. I took care of that problem but
now, when I turn one control to visible=true then do another only the last
one is visible.

Here is my code and an Immediate of the debug.prints.

In ThisWorkbook class module:

Option Explicit
Private pRibbonUI As IRibbonUI

Public Property Let ribbonUI(iRib As IRibbonUI)
'Set RibbonUI to property for later use
Set pRibbonUI = iRib
End Property


Public Property Get ribbonUI() As IRibbonUI
'Retrieve RibbonUI from property for use
Set ribbonUI = pRibbonUI
End Property

In Control module:
Public strControl As String, blnTrueFalse As Boolean

'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)
ThisWorkbook.ribbonUI = ribbon
Debug.Print "ribbon loaded at " & Time
Call WorkFlow
Debug.Print "rol exited " & Time
End Sub

Sub GetVisible(control As IRibbonControl, ByRef visible)
If control.Id = strControl Then
visible = blnTrueFalse
Debug.Print control.Id & " yes"
Else
Debug.Print control.Id & " no"
End If
End Sub

In Workflow Sub:

Debug.Print "invalidate"
blnTrueFalse = False
strControl = ""
ThisWorkbook.ribbonUI.Invalidate

Debug.Print "developer on"
If gbUserName = "Rick" Then 'show the developer tab
blnTrueFalse = True
Else
blnTrueFalse = False
End If
strControl = "CustomDeveloperTab"
ThisWorkbook.ribbonUI.InvalidateControl "CustomDeveloperTab"
blnTrueFalse = True
strControl = "CustomToolsTab"
ThisWorkbook.ribbonUI.InvalidateControl "CustomToolsTab"

Debug.Print "exit workflow"
Exit Sub


Resulting Immediate
**************************************
workbook exit at 7:07:12 PM
ribbon loaded at 7:07:12 PM
invalidate
developer on
exit workflow
rol exited 7:07:12 PM
rxGAD01 no
rxGAD02 no
rxGAD03 no
rxGAD04 no
CustomDeveloperTab no
CustomToolsTab yes

The major problem seems to be that the getVisible will only run once the
Ribbon_onLoad has terminated. And it is only getting the last command
(Custom tools).

Could someone please advise me how I can restructure this code so that I can
have the Ribbon_onLoad terminate before going into the workflow? Right now
it is called (because that is the only event that fires after the
ThisWorkbook terminates.

Thank you very much.

Rick
 
Ad

Advertisements

B

Bob Phillips

Ron de Bruin has reported problems with InvalidateControl. I play safe and
just use Ribbon.Invalidate all the time.

Bob
 

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