been too busy to post my example:, but here is my class object the bibbon
-->this is a class moddule called clsRibbon
Option Compare Database
Option Explicit
Public colControls As New Collection
Public m_ribbon As IRibbonUI
Private m_name As String
Public Property Get Controls(strC As String, Optional strRib As String = "")
As clsRibContorl
Dim i As Integer
Dim intGotOne As Integer
Dim NewControl As New clsRibContorl
' look for contorl in colleciton, if not in, then add...
For i = 1 To colControls.Count
If strC = colControls(i).name Then
intGotOne = i
Exit For
End If
Next i
If intGotOne = 0 Then
' add contorl, set defaults
NewControl.enabled = True
NewControl.visible = True
NewControl.Label = ""
NewControl.name = strC
colControls.Add NewControl, strC
Set Controls = NewControl
Else
Set Controls = colControls(intGotOne)
End If
Me.m_ribbon.InvalidateControl (strC)
End Property
Public Property Get MyControls(strC As String) As clsRibContorl
Dim i As Integer
Dim intGotOne As Integer
Dim NewControl As New clsRibContorl
' look for contorl in colleciton, if not in, then add...
For i = 1 To colControls.Count
If strC = colControls(i).name Then
intGotOne = i
Exit For
End If
Next i
If intGotOne = 0 Then
' add contorl, set defaults
NewControl.enabled = True
NewControl.visible = True
NewControl.Label = ""
NewControl.name = strC
colControls.Add NewControl, strC
Set MyControls = NewControl
Else
Set MyControls = colControls(intGotOne)
' If bolLoad = False Then
' Me.m_ribbon.InvalidateControl (strC)
' Me.m_ribbon.Invalidate
' End If
End If
End Property
Public Property Get name() As String
name = m_name
End Property
Public Property Let name(str As String)
m_name = str
End Property
--------------------
And, I also have a class for the contorl, it is called clsRibContorl
Option Compare Database
Option Explicit
Dim m_enabled As Boolean
Dim m_visible As Boolean
Dim m_Label As String
Dim m_name As String
Public Property Let enabled(bol As Boolean)
m_enabled = bol
End Property
Public Property Get enabled() As Boolean
enabled = m_enabled
End Property
'-----------
Public Property Let visible(bol As Boolean)
m_visible = bol
End Property
Public Property Get visible() As Boolean
visible = m_visible
End Property
Public Property Let Label(str As String)
m_Label = str
End Property
Public Property Get Label() As String
m_Label = m_Label
End Property
Public Property Get name() As String
name = m_name
End Property
Public Property Let name(str As String)
m_name = str
End Property
------
And, our standard code in a regular module (basRibbon) is:
Option Compare Database
Option Explicit
Public colRibbons As New Collection
Private f As Form
Public Sub SetMyRib(frm As Form, Optional strRibbonName As String = "")
Dim i As Integer
Set f = frm ' needed global from ref for MyRibbonLoad Call back
If strRibbonName = "" Then
strRibbonName = frm.name
End If
For i = 1 To colRibbons.Count
If colRibbons(i).name = frm.name Then
Set frm.MyRibbon = colRibbons(i)
Exit For
End If
Next i
frm.RibbonName = strRibbonName
End Sub
Public Sub MyRibbonLoad(ByRef nribbonUI As Office.IRibbonUI)
Dim colNewRib As New clsRibbon
colNewRib.name = f.name
Set colNewRib.m_ribbon = nribbonUI
colRibbons.Add colNewRib, f.name
Set f.MyRibbon = colNewRib
Set f = Nothing
End Sub
Public Sub MyVisible(control As IRibbonControl, _
ByRef visible As Variant)
Dim f As Form
If Forms.Count > 0 Then
Set f = Screen.ActiveForm
visible = colRibbons(f.name).MyControls(control.ID).visible
End If
End Sub
Public Sub MyEnable(control As IRibbonControl, _
ByRef visible As Variant)
Dim f As Form
Set f = Screen.ActiveForm
visible = colRibbons(f.name).MyControls(control.ID).enabled
End Sub
Now, for any form, do NOT use the "other tab" to set the ribbion, but in the
forms on-load go:
Call SetMyRib(Me)
Now, to enable, or make vistiatl any contorl inthe menu bar, you simply go:
MyRibbon.Controls("button1").enabled = True
or
MyRibbon.Controls("button1").enabled = false
So, you can now enable, disable any control in the ribbon you please. Note
that the above also allows you to specify a ribbon name
MyRibbon.Controls("button1", "name of ribbon").enabled = false
If you leave it blank, it assumes the current form name for the ribbon.
For ANY control that you need enable/disable, you add to the xml:
<button id="button1" label="Buttion1"
getVisible="MyVisible"
getEnabled="MyEnable"
onAction="=MyTest1()" />
the beauty of this whole system is that you don't need to write any
additional code for each new ribbon control that you want to enable, or
disable, or visible.
I just simply too busy to write up this code, document it, and post an
example. I will do so ASAP....
However, the above should get you going if you want a "general" solution for
all ribbons and not have to write additional code for each control....