My guess is that you're asking how to use the GetVisible callback to
control the visibility of certain controls in the ribbon.
Here's a simple example for a ribbon in which you want to special-case
a few of your buttons and have the others on unconditionally
Sub MyGetVisibleFcn(control As IRibbonControl, ByRef returnedVal)
Select Case control.id
Case "My1stButton"
returnedVal = IsButtonOn(1)
Case "My2ndButton"
returnedVal = IsButtonOn(2)
Case "My3rdButton"
returnedVal = IsButtonOn(3)
Case "My4thButton
returnedVal = NotIsButtonOn(1)
Case "My5thButton"
returnedVal = Not IsButtonOn(2)
Case "My6thButton"
returnedVal = Not IsButtonOn(3)
Case Else
returnedVal = True
End Select
End Sub
You then have to make sure that you put the
GetVisible="MyGetVisibleFcn" property in your ribbon.xml for any
controls that you want to control the visibility of. Each control's
GetVisible function will be called when the document opens.
If you want to manually trigger your GetVisible function in response
to some event, you need to invalidate the control. To invalidate the
control, you have to have the ribbon's handle (the IRibbonUI handle).
As far as I can tell, you can only grab that handle when your document
is opened (or created), which you do by creating an Onload function
for the ribbon, and adding the onLoad property to your ribbon.xml
file:
<customUI xmlns="
http://schemas.microsoft.com/office/2006/01/customui"
onLoad="MyRibbonLoadFcn">
Dim ribbonHdl as IRibbonUi
Sub MyRibbonLoadFcn(ribbon As IRibbonUI)
Set mRibbon = ribbon
End Sub
Then you can write a function that invalidates controls, which forces
their GetVisible to be called:
Sub InvalidateButton(buttonName)
'Whatever logic you need to make your MyGetVisibleFcn work
' correctly for the button when it gets called, then:
call mRibbon.InvalidateControl(buttonName)
End Sub
- Gary