Working with Addins & COMAddins and Excel User Defined Functions

C

Craig Dunstan

I have created a COMAddin for excel using VSTO 2005SE (ThisAddin) and also a
separate Automation Addin to present user defined functions that can be
called by Excel.

How do reference the data in one from the other? From (ThisAddin)
This.Application.COMAddins, I do not see the automation addin, but from
This.Application.Addins I do, however there does not seem to be a way to get
a reference to the running instance.

Is there a way to combine the two into one, for example, and access a
function from the ThisAddin class from within Excel? I can't get my head
around what mechanism makes the function visible to Excel.

Any thoughts would be greatly appreciated.

Regards
Craig.
 
C

Cindy M.

Hi =?Utf-8?B?Q3JhaWcgRHVuc3Rhbg==?=,
I have created a COMAddin for excel using VSTO 2005SE (ThisAddin) and also a
separate Automation Addin to present user defined functions that can be
called by Excel.

How do reference the data in one from the other? From (ThisAddin)
This.Application.COMAddins, I do not see the automation addin, but from
This.Application.Addins I do, however there does not seem to be a way to get
a reference to the running instance.

Is there a way to combine the two into one, for example, and access a
function from the ThisAddin class from within Excel? I can't get my head
around what mechanism makes the function visible to Excel.
I've never tried this with a 2005SE Add-in, but it should be the same as with
any other COM-Addin (whether managed or unmanaged code). Andrew Whitechapel has
a detailed discussion in his book ".NET development for Office". Basically, you
need to add a REFERENCE (as in Tools/References in the VB Editor) to the
Add-in's dll, just as for any other external project you want to use. Then you
can declare object variables with the types exposed by the class and thus gain
access to its methods and properties.

Dim o As COMAddinProjectName.Object

Set o = New COMAddinProjectName.Object
o.MethodName

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Craig Dunstan

Thanks for your reply Cindy, although I have tried this and seem to get a
different instance of the object. So for example, I have a function which is
presented through COM to Excel which allows me to call a function
ApprovedPrice(string custid, string productid) and this looks up an in memory
pricebook for the lowest approved price we have for that customer....

Using the add-in, I then have written a number of functions to allow me to
update the pricebook from various sources, but I'm working on a different
instance of the object. I can see what appears to be a list of COM add-ins
that are loaded, but I can't seem to find a way to reference the instance
that is loaded.

BTW, all of this is going on within the same assembly. Regards
 
C

Cindy M.

Hi =?Utf-8?B?Q3JhaWcgRHVuc3Rhbg==?=,
Thanks for your reply Cindy, although I have tried this and seem to get a
different instance of the object. So for example, I have a function which is
presented through COM to Excel which allows me to call a function
ApprovedPrice(string custid, string productid) and this looks up an in memory
pricebook for the lowest approved price we have for that customer....

Using the add-in, I then have written a number of functions to allow me to
update the pricebook from various sources, but I'm working on a different
instance of the object. I can see what appears to be a list of COM add-ins
that are loaded, but I can't seem to find a way to reference the instance
that is loaded.
I don't think there is any way to access an instance created by "something
else". When you access functions in another Addin you have to create an instance
in order to do that. An instance "belongs" to whatever created it. I think you'd
need to persist the information in memory to an "open source" (file? WebService?
Database? Static members?) so that all instances have access to it.

The only kinds of "instances" I'm aware of that one can link into are
applications that expose an automation interface. Those can be picked up as
Processes using .NET applications. But I don't think an Add-in dll exposes a
Process. I could be wrong about that, though, as this is getting way outside my
area of expertise/experience. You could try asking about this in the
dotnet.framework.interop newsgroup. But it seems a bit "dangerous" to me...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
A

AnnaF

Hello Craig, Cindy;

I had same problem and solved it through a Named Event. The event was
created by COM and reopened in automation add-in where a waiting function was
placed in a separate thread. Kind of inter-process communication...

Regards,
Anna F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top