Custom Ribbon works, but how do I enable/disable icons

thatlem

Registered User.
Local time
Yesterday, 23:50
Joined
Jan 29, 2009
Messages
115
When building the custom user interface ribbon, I used groups just as much as possible. However, on a few groups, I had to build the pieces I wanted.

They work great, but they basically are turned on all the time. If you click on one when not appropriate, you get a macro error and the option to disable ALL macros - not something I want the end user to be able to do.

I understand there is an enable function that can be written into the XML script, but don't understand how I will enable and disable as the user moves through the application. Web searchs have been little help.

Any explaination would help. :D
 
Hi,

have a look at the "GetEnabled" feature.

how did you set up your ribbon for visability? did you use GetVisible?

you want something like-
Code:
[FONT=Arial][COLOR=#0000ff]
<[/COLOR][/FONT][FONT=Arial][SIZE=2][COLOR=#800000]customUI[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#ff0000]xmlns[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2]"[/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#000000]http://schemas.microsoft.com/office/2006/01/customui[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2]"[COLOR=#0000ff]>
    [/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]commands[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>

        <[/COLOR][/SIZE][SIZE=2][COLOR=#800000]command[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]idMso[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]Cut[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]onAction[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]CallbackCut[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"
[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]          [COLOR=Red][B]getEnabled[/B][/COLOR][/COLOR][/SIZE][SIZE=2][COLOR=Red]=[/COLOR][/SIZE][SIZE=2][COLOR=Red]"[/COLOR][/SIZE][SIZE=2][COLOR=Red]CallbackGetEnabled[/COLOR][/SIZE][SIZE=2][COLOR=Red]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][COLOR=Red]/>[/COLOR]
        <[/COLOR][/SIZE][SIZE=2][COLOR=#800000]command[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]idMso[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]Copy[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]onAction[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#000000]CallbackCopy[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]/>

    </[/COLOR][/SIZE][SIZE=2][COLOR=#800000]commands[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE]
</[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#800000]customUI[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2][COLOR=#0000ff]> 
[/COLOR][/SIZE][/FONT]

note the line in red ( getEnabled )

the callback
Code:
[FONT=Arial][COLOR=#0000ff]Option Compare Database
Option Explicit[/COLOR][/FONT] [FONT=Arial][SIZE=2][COLOR=#000000][COLOR=#0000ff]Public[/COLOR] bolEnabled [COLOR=#0000ff]As Boolean[/COLOR][/COLOR][/SIZE][/FONT]
 [FONT=Arial][SIZE=2][COLOR=#000000][COLOR=#0000ff]Sub[/COLOR] CallbackGetEnabled(control [COLOR=#0000ff]As[/COLOR] IRibbonControl, _
                       [COLOR=#0000ff]ByRef[/COLOR] enabled)
[COLOR=#006600]' Callback getEnabled[/COLOR][/COLOR][/SIZE][/FONT]
 [FONT=Arial][SIZE=2][COLOR=#000000]    enabled = bolEnabled[/COLOR][/SIZE][/FONT]
 [FONT=Arial][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]End Sub[/COLOR][/COLOR][/SIZE][/FONT]


say for example, you wanted a button not to be enabled, then you set a routine to set bolEnabled = false. you then invalidate the ribbon to force the change


to invalidate the ribbon, use something like-


Code:
[FONT=Arial][COLOR=#0000ff]Option Compare Database
Option Explicit[/COLOR][/FONT]
 [FONT=Arial][COLOR=#000000][COLOR=#0000ff]Public[/COLOR] gobjRibbon [COLOR=#0000ff]As[/COLOR] IRibbonUI[/COLOR][/FONT]
 [FONT=Arial][COLOR=#000000][COLOR=#0000ff]Sub[/COLOR] CallbackOnLoad(ribbon As IRibbonUI)
   [COLOR=#006600] ' Cache a copy of RibbonUI.[/COLOR]
    
    [COLOR=#0000ff]Set[/COLOR] gobjRibbon = ribbon
    
[/COLOR][COLOR=#0000ff]End Sub[/COLOR][/FONT]


you would use this
Code:
[FONT=Arial][COLOR=#000000][B]gobjRibbon.InvalidateControl "ControlID"[/B][/COLOR][/FONT]
to invalidate the control and
Code:
[B]gobjRibbon.Invalidate[/B]
to invalidate the whole ribbon.


personally, i opted for a removal of the ribbon items i didnt want to save any confusion as originally, i had buttons enabled disabled and had lots of questions like, why are my buttons disabled"! once i removed them from site, everyone was happy :)


regs

Nigel


 

Users who are viewing this thread

Back
Top Bottom