0

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.