Using CommandBar to customize ribbon in COM-Addin

838 views Asked by At

I am trying to add a button to the ribbon using CommandBars, but I can't find any example or a way to do that.

I cannot use the CustomUI XML because I need to change the visibility of the button, and it is not supported by the CustomUI XML.

I have found a CommandBar called "Ribbon" with a CommandBarControl that is called "Ribbon" as well, but I don't see how I use it to place a button on "TabHome".

Does anyone know what am I missing here? or can point me out to an example?

Thanks!

1

There are 1 answers

3
Nikolay On BEST ANSWER

As far as I know, you can't use CommandBars to control ribbon. And it makes no sense to do so, as CommandBars technology is depreciated for ribbon ui, and basically supported for compatibility only.

Did not quite get why you don't want to use ribbon xml to customize ribbon? It's the official way. To control button visibility, you should simply set a "getVisible" attribute of the button to your event handler (callback) and and in that callback return true/false to show/hide the button...

What you can't show/hide dynamically are built-in office buttons, but you should be able to show/hide your own buttons without any issues.

Looks quite similar to this one:

Is there a way to use VBA and XML to add a button to the Office 2010 Ribbon depending on a string in the file name?