Writing an Excel COM AddIn

Writing a plugin in C# for Excel

There are not a lot of references that actually tell you how to do this. There are many that tell you partially how to do it, but they don't give you the full info.

This might now be out-of-date - I think you can do this much more straightforwardly in Excel 2007

We will be writing an "In-Process" COM add-in

Write An Interface for the functions you want to implement.

Write an implementation for the interface

Add in COM interop stuff.

Note that quite a few places will tell you to use ClassInterfaceType.AutoDual. Don't. All that does is 'magically' write an interface for this function to export, as it is the interface thats exposed, not the class. By writing the interface, you save that bother.

Note also that only the first named interface is exposed, so if you need multiple interfaces, you will need to create a superinterface for them all.

Write an implementation for IDTExtensibility2 interface.

This allows you to listen in to when your add-in gets loaded and unloaded. It will allow you to add and remove menus too.

Add reference to Extensibility.dll, and Office Objects v11.

Note that only the first interface is exposed to COM, so the IDTExtensibility2 thing shouldn't show up.

Add in to Excel

It will be under Tools, Add Ins, Automation

Disting it out

When building an MSI, for some reason I couldn't get it ro register the assembly automatically.

run:

c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\RegAsm /codebase yourdll.dll

from the deployment directory.

References

http://blogs.msdn.com/eric_carter/archive/2004/12/01/273127.aspx

Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account. You can also Sign Up for a new account.


Browse Space

- Pages
- Blog
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced
- Activity

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content

- Add Comment