Click here to Skip to main content
13,865,159 members
Click here to Skip to main content
Add your own
alternative version


81 bookmarked
Posted 18 Jul 2004

Create an Automation Add-In for Excel using .NET

, 3 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Describes how to create an automation add-in for Excel using .NET.


Excel versions 2002 (XP) and 2003 introduce the concept of an Automation Add-In. Automation Add-Ins allow public functions in COM libraries to act as User-Defined Functions (UDFs) in Excel, thus to be referenced directly from cell formulae.

This article provides a detailed walk-through of how to create an Automation Add-In for Excel using Visual Studio .NET.


Some relevant knowledge base articles that discuss Automation Add-Ins are:

  • Q291392 - INFO: Excel COM Add-ins and Automation Add-ins.
  • Q285337 - How To Create a Visual Basic Automation Add-in for Excel Worksheet Functions.
  • Q278328 - XL2002: How to Mark an Automation Add-In Function as Volatile.

A commercial library that presents equivalent (and more) functionality, and makes this all very easy is ManagedXLL. However, this library is quite expensive and requires run-time licenses to distribute user code. It uses the native XLL API for creating an add-in to Excel, and thus also supports older versions of Excel.

The exact requirements for creating a COM server that can be used as an Automation Add-In are poorly documented, complicated by the fact that the default options in Visual Basic 6.0 seem to work perfectly.

When creating a COM library using .NET, an attempt to add the library as an Automation Add-In in Excel causes the error: “The file you selected does not contain a new Automation Server, or you do not have sufficient privileges to register the Automation Server”.

Here, I describe how to create an Automation Add-In in .NET, using C#. The techniques should apply to any .NET language.

There seem to be three tricks for implementing an Automation Add-In for Excel using .NET:

  1. The library needs to be registered for use through COM. This can be done by marking the project to ‘Register for COM Interop’ or by manual registration using RegAsm.exe.
  2. The ‘Programmable’ registry key needs to be added in the registry, under HKCR\CLSID\{xxx}\. This can be automated by adding appropriate ComRegisterFunction methods to the class.
  3. The class needs to be marked with the ClassInterface attribute, with value ClassInterfaceType.AutoDual (explicit interface implementations can work too). The default class interface that is generated is a dispatch interface - Excel seems to ignore the dispatch interface for Automation Add-Ins.


  1. Create the library:
    1. Create a new C# Class Library Project, called NAddIn.
    2. Select the project's properties; under ‘Configuration Properties’, ‘Build’, set ‘Register for COM Interop’ to True.
    3. Rename the class, add a namespace declaration, set the ClassInterface attribute of the class, and add a function to be used from Excel:
      using System;
      using System.Runtime.InteropServices;
      namespace NAddIn
          public class Functions
              public Functions()
              public double Add2(double v1, double v2)
                  return v1 + v2;
              public static void RegisterFunction(Type t)
                      "CLSID\\{" + t.GUID.ToString().ToUpper() + 
              public static void UnregisterFunction(Type t)
                      "CLSID\\{" + t.GUID.ToString().ToUpper() + 
    4. Build the NAddIn project to create bin\debug\NAddIn.dll.
  2. Test the Add-In in Excel:
    1. Open a new workbook in Excel.
    2. Select Tools, Add-Ins, Automation.
    3. NAddIn.Functions should be listed - select it. OK.
    4. In a cell, type =Add2(3,4)
    5. The cell should display 7.
To register the .dll after moving it, run regasm with the
flag (typically as
        /codebase NAddIn.dll
). You will get a warning about the assembly being unsigned - you can ignore this (or sign the assembly as documented).


  1. Initial version - 19 July 2004.
  2. Removed type library embedding instructions - 19 July 2004.
  3. Added ComRegisterFunction bits to automate registry changes - 30 July 2004.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Govert van Drimmelen
Web Developer
South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralRe: To attach to a Com+ Application Pin
E. del Ayre17-Jan-07 23:41
memberE. del Ayre17-Jan-07 23:41 
QuestionAutomatic activation add-in Pin
Sergey Morenko12-Nov-06 4:21
professionalSergey Morenko12-Nov-06 4:21 
AnswerRe: Automatic activation add-in Pin
rkapl18-Sep-07 6:20
memberrkapl18-Sep-07 6:20 
QuestionCan't shown on Insert Function Formular? Pin
jluo029-Nov-06 13:41
memberjluo029-Nov-06 13:41 
GeneralFunction of an another Pin
Shurka20-Oct-06 4:52
memberShurka20-Oct-06 4:52 
GeneralRe: Function of an another Pin
Govert van Drimmelen20-Oct-06 5:36
memberGovert van Drimmelen20-Oct-06 5:36 
GeneralRe: Function of an another Pin
Shurka22-Oct-06 23:01
memberShurka22-Oct-06 23:01 
GeneralRe: Function of an another Pin
yg700121-Aug-08 20:30
memberyg700121-Aug-08 20:30 
QuestionType library embedding Pin
trias1028-Aug-06 8:44
membertrias1028-Aug-06 8:44 
GeneralFunctions are not refreshed Pin
PAU_CARRE8-Aug-06 7:33
memberPAU_CARRE8-Aug-06 7:33 
GeneralRe: Functions are not refreshed Pin
pinkfloydfan26-Oct-07 2:52
memberpinkfloydfan26-Oct-07 2:52 
GeneralC++/CLI Pin
davidward3024-Jun-06 2:28
memberdavidward3024-Jun-06 2:28 
GeneralRe: C++/CLI Pin
arnab.m9-Oct-07 14:43
memberarnab.m9-Oct-07 14:43 
GeneralRelocating plugin to another PC Pin
Manassypov26-May-06 11:17
memberManassypov26-May-06 11:17 
GeneralRe: Relocating plugin to another PC Pin
Jeltz126-May-06 21:42
memberJeltz126-May-06 21:42 
GeneralRe: Relocating plugin to another PC Pin
Manassypov27-May-06 4:34
memberManassypov27-May-06 4:34 
GeneralRe: Relocating plugin to another PC Pin
Jeltz127-May-06 5:20
memberJeltz127-May-06 5:20 
GeneralRe: Relocating plugin to another PC Pin
Govert van Drimmelen27-May-06 8:29
memberGovert van Drimmelen27-May-06 8:29 
GeneralI can't see it in automation Please help Pin
uzidr190028-Jan-06 0:07
memberuzidr190028-Jan-06 0:07 
GeneralRe: I can't see it in automation Please help Pin
m9628-Apr-06 10:53
memberm9628-Apr-06 10:53 
GeneralRe: I can't see it in automation Please help Pin
m968-May-06 14:48
memberm968-May-06 14:48 
GeneralRe: I can't see it in automation Please help Pin
Manassypov26-May-06 11:18
memberManassypov26-May-06 11:18 
GeneralRe: I can't see it in automation Please help Pin
Jeltz126-May-06 15:38
memberJeltz126-May-06 15:38 
GeneralRe: I can't see it in automation Please help Pin
Zully Ramos29-Feb-08 9:59
memberZully Ramos29-Feb-08 9:59 
GeneralRe: I can't see it in automation Please help Pin
Jeltz126-May-06 21:41
memberJeltz126-May-06 21:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 4 Aug 2004
Article Copyright 2004 by Govert van Drimmelen
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid