Hi Felix,
Thanks for reporting this problem. I hadn't realised that the Ribbon
ProgID is used in this way.
Investigating, it opens up a bit of a minefield. I'm haven't really
found a workaround yet.
This article is helpful:
http://www.excelguru.ca/blog/2007/03/19/sharing-a-custom-ribbon-tab-among-workbooks/
And in particular Andrei from Add-in Express had a very informative
comment.
So:
What is actually stored in the .qat is the namespace for the item you
have added to the QAT.
By default, as you say, the namespace is the ProgId for the ribbon
class, which in Excel-DNA currently changes at runtime.
(We had a similar issue for the RTD servers, and that is mostly
resolved in v. 0.29 by allowing you to set up a fixed ProgId.)
However, you can also override the workspace of a ribbon item by using
an idQ='x:MyButton' id instead of id='MyButton'.
The namespace is set in your CustomUI:
<customUI xmlns='
http://schemas.microsoft.com/office/2006/01/
customui' loadImage='LoadImage' xmlns:x='My.NameSpace'>
If you do this, then add the button to the QAT, Excel will store the
entry in the .qat file as My.Namespace, and it will recover it right
when restarting.
But there is a problem with this plan, which is what Andrei explained.
The callbacks to your class don't work if the class has a different
ProgId than the namespace. So by changing the namespace for your
customUI ids, you break the ribbon callbacks. I'm not sure if there is
a further workaround. So that doesn't really help us.
At runtime you would be able to change the ribbon .xml returned to
Excel, and fill in the new (dynamic) progId. I'm not sure how this
could help...
The real fix would be to use whatever [ProgId(...)] you set for your
Ribbon class, and for Excel-DNA to use that ProgId. This is already in
place for RTD servers and the custom COM Server classes, I just can't
see immediately whether it will work for ExcelRibbons too. Maybe if
you mark the ExcelRibbon-derived class with [ExcelComClass]? Maybe if
your ExcelRibbon-derived class also implements IRtdServer? If you
search through the COM Server posts in this group, you'll see how the
ComServer.RegisterServer... stuff can register a class with the right
ProgId. That might work for you already, I'm not sure yet.
I'll let you know more, after I've had a chance to experiment a bit
more.
Regards,
Govert