Reputation: 1
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
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:
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:
and press 'Enter' to see the result:
A great guide to porting code from VBA to VB.NET with Excel-DNA is available from Patrick O'Beirne.
Upvotes: 1