Link to home
Start Free TrialLog in
Avatar of doubl00
doubl00

asked on

Using C# to Build a COM Add-In Function as an Excel Worksheet function

Microsoft Knowledge Base has an article on "HowTo:  Use a COM Add-In Function as an Excel Worksheet Function"

http://support.microsoft.com/default.aspx?scid=kb;EN-US;256624

Can anyone help me to do the same thing with C#?  

I have tried two approaches:  

1.  Using the COMAdd-in Wizard and adding public functions to the connect class

2.  Build ing a library class, running regasm, giving a strong name and storing in the Global Assembly Cashe

In both cases I have referrenced the assembly in VBA for Excel and written a VBA wrapper per the above KB article.  

Any ideas?

Avatar of AColombi
AColombi

Have you verified that you can call methods of your class library in a standard COM setting?  Like VB6 or VBScript?

-Andrew
Avatar of doubl00

ASKER

I will try that with the code of method 2 above.      

In approach 1. above, The COMAddin loads and is visible in the COM Addin dialog.  I can view the "connect" class of the COMAddin but none of its methods.  

In approach 2. above, I have two classes in the library dll:  One has methods that take parameters and one has method that takes no parameters.  Both "classes" are visible in the object browser of the VBE.  However, only the parameterless "methods" are visible in the object browser.  

Documentation says .NET can only pass a public method and that the "class" must be derived froma efault (no parameters) in the COM object.  I don't think that means I can't pass parameters back to .NET in the methods, does it?  



ASKER CERTIFIED SOLUTION
Avatar of AColombi
AColombi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doubl00

ASKER

Thanks.  I was able to connect to my COM Server using approach 2 above.  

I thought I had used all the steps before, but maybe not all at the same time.  Your encouragement helped.  I was not using overloaded functions, but will remember that in the future.  

For others benefit, here is what I did:  
created a dll using C# (using an interface)
created a strong name
installed in the GAC
registered it for COM
referecned Excel (and Office) PIAs

in VBA, referenced the library
wrote a wrapper in VBA
instanciated the class in VBA

Thanks again