Home > other >  How to display a version # in a customUI ribbon
How to display a version # in a customUI ribbon

Time:09-23

I have a Excel VBA project where I expect to issue updates. It has a custom UI ribbon. For support purposes (screen captures), I want to display the app's version number in the ribbon, which would be read from a hidden sheet. I was hoping to do this with just a label control. But it does not appear that a label control has a callback. I thought I would try it with an Edit Box without an on_change capability. Unless I am using it wrong, InvalidateControl still allows me to type into the Edit Box.

Sub GetVersion(control As IRibbonControl, ByRef sVversion)
    sVversion = ThisWorkbook.Sheets("Sheet1").Range("A1").Text
    myRibbon.InvalidateControl "GetVersion"
End Sub

Does anyone have any suggestion?

Other ideas I have considered would be a button control that displays the version in a MsgBox or UserForm, or a button with no functionality and just displays a SuperTip.

CodePudding user response:

The labelControl provides the following callbacks and attributes:

enabled, getEnabled, getLabel, getScreentip, getShowLabel, getSupertip, getVisible, id, idMso, idQ, insertAfterMso, insertAfterQ, insertBeforeMso, insertBeforeQ, label, screentip, showLabel, supertip, tag, visible

The getLabel callback gets the label for a control and has the following signature:

C#: string GetLabel(IRibbonControl control)

VBA: Sub GetLabel(control As IRibbonControl, ByRef label)

C  : HRESULT GetLabel([in] IRibbonControl *pControl, [out, retval] BSTR *pbstrLabel)

Visual Basic: Function GetLabel(control As IRibbonControl) As String

It seems you have just chosen a wrong signature and the Office runtime can't locate the callback specified in the ribbon XML.

You can read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

  • Related