Build Excel Automation Add-in in C#, C++, VB.NET
Excel user-defined functions (UDF) in Visual Studio .NET
Add-in Express
for Microsoft .net
Add-in Express Home > Add-in Express.NET > Online Guide > Excel Automation
Excel Automation add-ins
In fact, the Excel Automation add-in (user-defined function, or UDF) does not differ from a COM add-in except for the registration in the registry. That's why Add-in Express bases Excel Automation Add-in projects on Add-in Express COM Add-in projects.
Add-in Express allows creating Automation add-ins for Excel 2007, 2003 and 2002 (XP). Add-in Express also provides some special features for creating an advanced user interface of your Excel add-in, such as custom task panes, XLL add-ins and more.
The sample Excel Automation addin below is written in VB.NET, while Visual C# and C++ are also supported.
Step #1 – Creating an Excel Automation add-in project
Choose the Add-in Express COM Add-in project template in the New Project dialog in the Visual Studio IDE.

When you select the template and click OK, the Add-n Express COM Add-in project wizard starts. In the wizard windows, you choose the programming language (it's Visual Basic in our project), setup project options, and Excel, as a supported application of your add-in.

This VB.NET sample shows an Add-n Express COM Add-in project implementing a COM add-in for Excel with the Add-n Express Loader as a shim. To understand shims and the Add-n Express Loader, see Deploying Add-in Express projects.

The Add-n Express Project wizard creates and opens the COM Add-in solution in Visual Studio. The solution includes the COM Add-in project and the setup project.

The COM Add-in project contains the AddinModule.vb (or AddinModule1.cs) file described on the Building your first Microsoft Office COM add-in page.
Step #2 – Adding a new Excel COM Add-in module
In order to add Excel user-defined functions to the COM add-in, you add the Excel COM Add-in module to the Add-n Express COM Add-in project using the Add New Item dialog.

This adds the ExcelAddinModule1.vb (or ExcelAddinModule1.cs) file to your COM Add-in project.

Step #3– Writing an Excel user-defined function
In the Solution Explorer window, right-click the ExcelAddinModule.vb (or ExcelAddinModule.cs) file and choose the View Code item in the context menu.

The module contains the following code:
Imports System.Runtime.InteropServices
'Add-in Express Excel Add-in Module
<GuidAttribute("287D044F-D233-47E6-BB48-35999635BAD3"), _
ProgIdAttribute("MyExcelAutomationAddin2.ExcelAddinModule1"), _
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class ExcelAddinModule1
Inherits AddinExpress.MSO.ADXExcelAddinModule
#Region " Add-in Express automatic code "
<ComRegisterFunctionAttribute()> _
Public Shared Sub AddinRegister(ByVal t As Type)
AddinExpress.MSO.ADXExcelAddinModule.ADXExcelAddinRegister(t)
End Sub
<ComUnregisterFunctionAttribute()> _
Public Shared Sub AddinUnregister(ByVal t As Type)
AddinExpress.MSO.ADXExcelAddinModule.ADXExcelAddinUnregister(t)
End Sub
#End Region
Public Sub New()
MyBase.New()
End Sub
End Class
Just add a new function to the module. Say, the following one:
Public Function MyFunc(ByVal Range As Object) As Object
MyFunc = CType(Range, Excel.Range).Value * 1000
End Function
Step #4 – Running the Excel Automation add-in
Choose the Register Add-n Express Project item in the Build menu, restart Excel, and check if your newly created Excel Automation add-in works.

Step #5 – Debugging the Excel Automation add-in
To debug your add-in, just specify Excel as the Start Program in the Project Options window.

However, when debugging an add-in in Visual Studio 2003 and Office 2002 (XP), you cannot see your add-in on the COM add-ins or AutoCorrect dialog box. This is a “feature” of Office XP "added" by Microsoft.
Step #6 – Deploying the Excel Automation add-in
Just built the setup project, copy all setup files to the target PC and run the setup.exe file to install your Excel Automation add-in.
Back to Add-in Express.NET homepage

