user2556523
user2556523

Reputation: 1

Create Excel UDFs in VSTO managed code

Anyone have a complete example in VB.Net 2010 and different from this:

http://blogs.msdn.com/b/pstubbs/archive/2004/12/31/344964.aspx http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/273127.aspx How to easily create an Excel UDF with VSTO Add-in project

Upvotes: 0

Views: 2929

Answers (1)

Govert
Govert

Reputation: 16907

As explained the StackOverflow question you link to, How to easily create an Excel UDF with VSTO Add-in project, VSTO does not support the creation of UDFs for Excel. Alternatives for VB.NET are to make COM Automation add-ins as per your other links, or to use something like the free Excel-DNA library (which I develop).

The easiest way to make an Excel UDF with Excel-DNA is to:

  • Create a new VB.NET Class Library project in Visual Studio.
  • 'Install-Package Excel-DNA' from Nu-Get.
  • Add a module with some code, compile and run.

Your first VB.NET function might look like this:

Imports ExcelDna.Integration
Public Module MyFunctions

    <ExcelFunction(Description:="My first .NET function")> _
    Public Function SayHello(name As String) As String
        Return "Hello " & name
    End Function

End Module

Then in Excel you enter the UDF as usual:

Enter Formula

and press 'Enter' to see the result:

Hello World!

A great guide to porting code from VBA to VB.NET with Excel-DNA is available from Patrick O'Beirne.

Upvotes: 1

Related Questions