1

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!

TCS
  • 5,790
  • 5
  • 54
  • 86

1 Answers1

1

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?

Community
  • 1
  • 1
Nikolay
  • 10,752
  • 2
  • 23
  • 51
  • Hey, thanks for you answer! The problem is that for some workbooks I want to return in getVisible() true, and for some I want to return false, but for some reason excel (for instance) doesn't call getVisible() more then once, and I cannot find a way to force excel to reask by calling "getVisible()". – TCS Jan 10 '14 at 22:07
  • 1
    you can forcie it using RibbonUI.Invalidate (or RibbonIU.InvalidateControl). You can get a reference to ribbonUI using OnLoad calback: http://msdn.microsoft.com/en-us/library/microsoft.office.core.iribbonui.invalidate.aspx, http://msdn.microsoft.com/en-us/library/office/ee390805.aspx – Nikolay Jan 10 '14 at 23:21
  • Thanks you! Just a little bit more extra detail, every time the group becomes invisible and turns to visible again, the image of the control (if getImage is defined) is being requested again. – TCS Jan 10 '14 at 23:26