In order to access the macros and functions I require in specific workbooks, which I can identify using various criteria, I have developed an add-in for Excel. Access is made simple with a ribbon tab. The ribbon tab shouldn't be shown when I (or other users) open a brand-new workbook or a workbook that doesn't meet the requirements, but it should be available when I move back to the right workbook. If I understand correctly, if the ribbon tab is in an xlsm, this happens automatically, but I need it in an external XLAM.
I had hoped that the getVisible="MyGetVisible" on the tab line would be able to serve as an on/off switch when it was set to True (for the wb where the ribbon tab should show) and False (for the others) and the ribbon was invalidated. However, the XLAM has XML code that looks like the below (some more, but this is the essential).
<tab id="MyTab" label="My Custom tab" insertBeforeMso="TabHome" getVisible="MyGetVisible">
<group idMso="GroupClipboard" />
<group id="MyGroup1" label="Sheet Navigation">
<dropDown id="MyDD1" label="Data Sheets" showLabel="false" imageMso="TextAlignGallery" getVisible="MyGetVisible2" getItemCount="MyGetItemCount" getItemID="MyGetItemID" sizeString="xxxxxxxxxx" getItemLabel="MyGetItemLabel" getSelectedItemID="MyGetSelectedItemID" onAction="MyOnAction"/>
And the VBA for MyGetVisible is
Public Sub GetVisible(control As IRibbonControl, ByRef visible)
visible = (ActiveWorkbook.name = "MyWBwhereTheRibbonTabShouldShow.xlsm")
Several of my tests using DoEvents and Wait are displayed in my RibRefresh. The issue is unrelated to the Ribbon ID being stored (although it seemed like it is safer to store the ID in a named cell in the xlam than to store it in a created name not referring to a range)
Public Sub RibRefresh()
If MyRibbon Is Nothing Then RibRetrieve
Application.Wait Now + 0.00001
If err.Number > 0 Then
MsgBox "The Ribbon-pointer is lost, save-close & restart workbook instead"
It seems like it should work, but it doesn't. Microsoft® Excel® for Microsoft 365 MSO (Version 2208 Build 16.0.15601.20526) 32-bit