views:

142

answers:

3

I see plenty on the web about VSTO and automating excel from c#, but very little to get started on wiring up a c# assembly to make it visible from Excel.

Can someone point me to some very basic info explaining how to create a COM interface, GUIDS, ComVisible etc?

+2  A: 

There are many books out there that might get you going. "Pro C# 2008" from Wrox has a great chapter on this.

Also, here is a MSDN blog article about COM Visible to Excel.

Mitchel Sellers
+2  A: 

Basically all you need to do is

  1. Make your assembly COM visible using the respective attribute in the project property Assembly version information dialog
  2. For every public class, add the following block (see [1]) of code above the class definition
  3. Register DLL using the regasm.exe tool found in the .NET 2 installation folder

Also, make sure to add a descriptive name to both application name and description in the Assembly version information dialog (they are later used to pick the COM classes).

[1] Block of code to add before class definition:

[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("SomeNameHere")]
[ComVisible(true)]
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx")]

After that you should be able to use the class like any other normal COM class.

EDIT
It should be noted that I do not have experience with Excel and C# COM classes - I'm using C# together with Microsoft Navision, which works great the way I described above.

Thorsten Dittmar
+1  A: 

Rather than go down the COM route, it is considerably easier (and less of an install issue) to use something like ExcelDNA. It allow you to write XLLs in .Net that don't require registering. It is also open-source and very well community supported.

Simon Pearson
I shall have to look into this. thanks
Nick