Search code examples
vb.netvstoribbon

How do you change the KeyTip property of a VSTO AddIn ribbon?


I am trying to change the KeyTip property of the RibbonTab object I have created. When I run my addin in Excel it shows the KeyTip is "X" and not "JJJ".

If I change it in the Properties window to "JJJ" it works fine but I want to understand why I cannot change it this way.

What do I need to do to get the RibbonTab.KeyTip property to load as "JJJ"?

(FYI this is my first project so I am still learning)

Thanks,

Imports Microsoft.Office.Tools.Ribbon

Public Class Ribbon1

Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load

   tabRibbon1.KeyTip = "JJJ"

End Sub

Solution

  • The Fluent UI (aka Ribbon UI) is a static thing from its birth. You may set up the keytip attribute only once at startup when your add-in returns the UI markup (generated by the Ribbon designer or just a raw XML markup).

    Also you may consider using the getKeyTip callback which allows to evaluate keyboard shortcuts dynamically. The Invalidate method of the IRibbonUI interface invalidates the cached values for all of the controls of the Ribbon user interface. You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method. For example:

    Dim MyRibbon As IRibbonUI 
    
    Sub MyAddInInitialize(Ribbon As IRibbonUI) 
      Set MyRibbon = Ribbon 
    End Sub 
    
    Sub myFunction() 
      MyRibbon.Invalidate() ‘ Invalidates the caches of all of this add-in’s controls 
    End Sub
    

    You may also find the InvalidateControl method of the IRibbonUI interface helpful. It invalidates the cached value for a single control on the Ribbon user interface.

    Read more about the Ribbon UI in the following series of articles:

    and