From: Neil Humphries on
Thank you again for your help.

"When computers (hardware and software) are as reliable as a hammer, then
they will be tools and not toys"

"Greg Maxey" wrote:

> Neil,
>
> I don't think you can ivalidate a group and all its controls with one
> statement. You can invalidate all of the controls in a group which would
> probably be better than invalidating the entire ribbon.
>
> Something like this:
>
> Dim arrControls() As String
> Dim i As Long
> arrControls = Split("myTB1|myTestButton1|myTestButton2", "|") '** the
> controls in a group
> For i = 0 To UBound(arrControls)
> myRibbon.InvalidateControl (arrControls(i))
> Next i
>
> According to documentatin the separator is "supposed" to take a static and
> dynamic "visible" attribute. However, it doesn't work and must be a bug.
>
>
>
>
> Neil Humphries wrote:
> > That is what I needed. Thanks.
> >
> > Is it possible or advantageous to invalidate a group and all it's
> > controls rather than the whole ribbon?
> >
> > I filter what is toggled by the tag property however I just
> > discovered that separators don't have a tag property. That seems odd
> > and will force more convoluted logic to control their visibility.
> >
> > Sub getVisible(control As IRibbonControl, ByRef visible)
> > MyTag = "TDRFP"
> > If MyPressed Then
> > If control.Tag Like MyTag Then
> > visible = False
> > ElseIf control.Tag = "show" Then
> > visible = True
> > End If
> > Debug.Print "Control id is like ", control.ID
> > If control.ID Like "SepMaxAdmin" Then
> > visible = False
> > End If
> > Else
> > visible = True
> > End If
> > End Sub
> >
> > My separators have ID's of SepMaxAdmin2 and SepMaxAdmin3.
> > <separator id="SepMaxAdmin2" getVisible="getVisible" />
> > <separator id="SepMaxAdmin3" getVisible="getVisible" />
> >
> > The following code has no effect on their visibility:
> > If control.ID Like "SepMaxAdmin" Then
> > visible = False
> > End If
> >
> > Any suggestions?
> >
> > "Greg Maxey" wrote:
> >
> >> Neil,
> >>
> >> I can't say this is the only way, but the way I do it is to
> >> invalidate the ribbon. The following XML and code shows a Ribbon
> >> with a functional toggle button that will show or hide a Test Button
> >> 1 control:
> >>
> >> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> >> <customUI
> >> xmlns="http://schemas.microsoft.com/office/2006/01/customui"
> >> onLoad="Onload"> <ribbon>
> >> <tabs>
> >> <tab id="CustomTab" label="My Tab">
> >> <group id="SampleGroup" label="Sample Group">
> >> <toggleButton id="myTB1" size="large" getLabel="GetLabel"
> >> getPressed="GetPressed" getImage="GetImage"
> >> onAction="MyActionMacro"/> <button id="myTestButton1" label="Test
> >> Button 1" getVisible="GetVisible"/> </group>
> >> </tab>
> >> </tabs>
> >> </ribbon>
> >> </customUI>
> >>
> >>
> >> Option Explicit
> >> Public myRibbon As IRibbonUI
> >> Private bState As Boolean
> >> Sub Onload(ribbon As IRibbonUI)
> >> Set myRibbon = ribbon
> >> bState = True 'Set initial state of toggle button (condition, label,
> >> image) End Sub
> >>
> >> Sub GetImage(control As IRibbonControl, ByRef image)
> >> Select Case control.ID
> >> Case "myTB1"
> >> If bState Then
> >> image = "FileOpen"
> >> Else
> >> image = "FileClose"
> >> End If
> >> Case Else
> >> 'Do Nothing
> >> End Select
> >> End Sub
> >>
> >> Sub GetPressed(control As IRibbonControl, ByRef state)
> >> If bState Then
> >> state = False 'Not depressed
> >> Else
> >> state = True 'Depressed
> >> End If
> >> 'You can use the GetPressed callback to perform simple toggle
> >> actions e.g.,: If Selection.Font.Size = 12 Then
> >> Selection.Font.Size = 6
> >> Else
> >> Selection.Font.Size = 12
> >> End If
> >> End Sub
> >>
> >> Sub MyActionMacro(ByVal control As IRibbonControl, pressed As
> >> Boolean) 'pressed is true if the toggle is clicked while in the "not
> >> depressed" state.
> >> If pressed Then
> >> bState = False
> >> MsgBox "The folder is shutting"
> >> Selection.Font.Color = wdColorRed
> >> Else
> >> bState = True
> >> MsgBox "The folder is opening"
> >> Selection.Font.Color = wdColorAutomatic
> >> End If
> >> myRibbon.Invalidate
> >> End Sub
> >>
> >> Sub getLabel(ByVal control As IRibbonControl, ByRef label)
> >> Select Case control.ID
> >> Case "myTB1"
> >> Select Case bState
> >> Case True
> >> label = "Open"
> >> Case Else
> >> label = "Shut"
> >> End Select
> >> Case Else
> >> 'Do nothing
> >> End Select
> >> End Sub
> >>
> >> Sub GetVisible(ByVal control As IRibbonControl, ByRef returnedVal)
> >> Select Case control.ID
> >> Case "myTestButton1"
> >> If bState Then
> >> returnedVal = True
> >> Else
> >> returnedVal = False
> >> End If
> >> End Select
> >> End Sub
> >>
> >> Neil Humphries wrote:
> >>> I have resolved the appearance & labelling of the toggle button. I
> >>> needed to change the onAction callback to pressed as boolean rather
> >>> then ByRef pressed or ByVal pressed, then clean up the togglestate
> >>> logic.
> >>>
> >>> That leaves me with wanting to use the togglestate of this button to
> >>> control the visibility of other controls in the same group. How do I
> >>> iterate through the other controls and can I manipulate the visible
> >>> attribute directly or do I have to use
> >>> getVisible in the XML for the control?
> >>>
> >>>
> >>> "Neil Humphries" wrote:
> >>>
> >>>> I must be missing something basic. I am trying to program a
> >>>> togglebutton to change labels based on whether it is pressed or
> >>>> not, but can't get it to work. As long as MyRibbon is valid,
> >>>> nothing changes. If because of editting VBA MyRibbon becomes
> >>>> invalid the button shows its toggled state. This is the code I am
> >>>> using:
> >>>>
> >>>> 'Callback for tButMAXAdmin00 onAction
> >>>> Sub MinimizeMaxAdminRFPBar(control As IRibbonControl, ByVal
> >>>> pressed) MyPressed = pressed
> >>>> If (Not MyRibbon Is Nothing) Then
> >>>> MyRibbon.InvalidateControl ("tButMAXAdmin00")
> >>>> End If
> >>>> End Sub
> >>>>
> >>>> Sub getVisible(control As IRibbonControl, ByRef visible)
> >>>> MyTag = "TDRFP"
> >>>> 'if max/min button pressed
> >>>> If control.Tag = "show" Then
> >>>> visible = True
> >>>> 'toggle visibility of other controls in same group
> >>>> If control.Tag Like MyTag Then
> >>>> visible = Not (visible)
> >>>> End If
> >>>> End If
> >>>> End Sub
> >>>>
> >>>> Sub getLabel(control As IRibbonControl, ByRef label)
> >>>> Select Case control.ID
> >>>> Case Is = "cButMAXAdmin99"
> >>>> 'this doesn't work because label is undefined when
> >>>> passed ByRef If label = "Minimize Group" Then
> >>>> label = "Maximize Group"
> >>>> Else
> >>>> label = "Minimize Group"
> >>>> End If
> >>>> Case Is = "tButMAXAdmin00"
> >>>> If MyPressed Then
> >>>> label = "Maximize Group"
> >>>> Else
> >>>> label = "Minimize Group"
> >>>> End If
> >>>> Case Else
> >>>> 'do nothing
> >>>> End Select
> >>>> End Sub
> >>>>
> >>>> Sub getPressed(control As IRibbonControl, ByRef toggleState)
> >>>> Select Case control.ID
> >>>> Case Is = "tButMAXAdmin00"
> >>>> MyPressed = Not (MyPressed)
> >>>> Case Else
> >>>> 'do nothing
> >>>> End Select
> >>>> toggleState = MyPressed
> >>>> End Sub
> >>>>
> >>>> If I want to use the togglestate of this button to control the
> >>>> visibility of other controls in the same group, how do I iterate
> >>>> through the other controls and can I manipulate the visible
> >>>> attribute directly or do I have to use getVisible in the XML for
> >>>> the control?
> >>
> >> --
> >> Greg Maxey
> >>
> >> See my web site http://gregmaxey.mvps.org
> >> for an eclectic collection of Word Tips.
> >>
> >> "It is not the critic who counts, not the man who points out how the
> >> strong man stumbles, or where the doer of deeds could have done them
> >> better. The credit belongs to the man in the arena, whose face is
> >> marred by dust and sweat and blood, who strives valiantly...who knows
> >> the great enthusiasms, the great devotions, who spends himself in a
> >> worthy cause, who at the best knows in the end the triumph of high
> >> achievement, and who at the worst, if he fails, at least fails while
> >> daring greatly, so that his place shall never be with those cold and
> >> timid souls who have never known neither victory nor defeat." - TR
>
> --
> Greg Maxey
>
> See my web site http://gregmaxey.mvps.org
> for an eclectic collection of Word Tips.
>
> "It is not the critic who counts, not the man who points out how the
> strong man stumbles, or where the doer of deeds could have done them
> better. The credit belongs to the man in the arena, whose face is
> marred by dust and sweat and blood, who strives valiantly...who knows
> the great enthusiasms, the great devotions, who spends himself in a
> worthy cause, who at the best knows in the end the triumph of high
> achievement, and who at the worst, if he fails, at least fails while
> daring greatly, so that his place shall never be with those cold and
> timid souls who have never known neither victory nor defeat." - TR
>
>
>
>