As you have discovered, Excel caches the state of ribbon controls. The only way to do what you want to do is to invalidate the ribbon/controls every time you have a state change that affects them. So in your case, whenever API.URL
changes, you need to manually invalidate the ribbon or controls.
1) Include the onLoad
attribute in your customUI
XML.
<customUI ... onLoad="OnRibbonLoad" ...>
...
</customUI>
2) In your callback, store the ribbon interface:
private IRibbonUI _ribbon;
public void OnRibbonLoad(IRibbonUI ribbon)
{
_ribbon = ribbon;
}
3) Later, when you have a state change that affects the ribbon, invalidate the ribbon or its controls:
...
_ribbon.Invalidate();
// or //
_ribbon.InvalidateControl("YourControlID");
...