Hey John,
My experience with this is that only ONE instance of your COM Addin is
ever loaded. And although more than one instance of your Automation
Addin class implementing IDTExtensibility2 can be, it's rare that it is
(and this is fully under your control).
The key though, again, is that only one instance of the COM Addin is
loaded. To test this, create a public long variable and have it
incremented by 1 in your Sub Main() startup that the 'COM Addin' will
call when loaded and also report that value via a MsgBox "Main:" &
CStr(myLongVar) and it will return "Main:1" as its result.
Then reference that variable in the 'IDTExtensibility2_OnConnection()'
routine (but don't increment it), calling MsgBox "IDTX:" &
CStr(myLongVar). The result will be "IDTX:1". The key here is that it
is returning 1, not zero.
(I just did this with my addin, which is doing some VERY complex things
at load-up, and so I can't be 100% sure if this is standard behavior,
but I'm pretty sure that it is.)
Anyway, what I would do is, have an internal, Public variable and call
it, say, 'myAddinInst'. Then within the IDTExtensibility2_OnConnection()
sub, set myAddinInst= Me. Thereafter this value can be accessed from
the 'COM Addin' side of the fence.
The one catch I can think of is that I do not think that the Automation
Addin even loads at all until one of its UDFs is actually called from
the Worksheet. So this means that when Excel starts up, your COM Addin
is loading and the 'myAddinInst' will be Nothing. So, what you can do to
"force the issue" is within your Sub Main(), call Evaluate() on any of
your UDFs, this will force Excel to load the Automation Addin located at
the ProgID that is specified, which causes the
IDTExtensibility2_OnConnection() sub to run, where your code sets
myAddinInst= Me. From that point onward the COM Addin has its
'myAddinInst' that it can use at will.
There's a lot of moving parts here, so I cannot GUARANTEE that the above
will work, but I'm fairly confident...
Let us know how it goes!
Mike
VBTalk .NET Office Automation:
http://www.xtremevbtalk.com/forumdisplay.php?f=105
*** Sent via Developersdex
http://www.developersdex.com ***