This project has moved. For the latest updates, please go here.

How to add / implement a worksheet function

Dec 17, 2013 at 2:16 AM
Dear members, I've a sample function which I've inserted in to the NetOffice 1.6.0\NET 4.0\Examples\Excel\VB\COMAddin Examples. But this function is inaccessible as a worksheet function.
Public Function AddThem(ByVal x, ByVal y)
    AddThem = x + y
End Function
  1. How can I access the function in worksheets?
  2. Is it possible to show the functions in a category like "MyFunctions"
Jan 20, 2014 at 12:45 PM
For managed Excel add-ins that contain UDF worksheet functions, Excel-DNA (http://exceldna.codeplex.com) is the best tool. You can still you the NetOffice libraries to give you version-independent access to the Excel COM object model. But Excel-DNA integrates with Excel through the C API, which gives the best performance and flexibility for UDFs - including customizing the Function Arguments dialog.

With Excel-DNA you could write your function as:
Imports ExcelDna.Integration

Public Module MyFunctions

    <ExcelFunction(Description:="My number adding function", Category:="My useful functions")> _
    Public Function AddThem(x As Double, y As Double) As Double
        AddThem = x + y
    End Function

End Module
-Govert
Feb 1, 2014 at 1:58 PM
Dear govert,
Thank you for your valuable information regarding ExcelDNA project. I'm currently exploring the same. In the mean time I came to know that you have developed this project. Really appreciate it.