Function categories

48 views
Skip to first unread message

Anthony Taylor

unread,
Aug 1, 2021, 4:06:52 PM8/1/21
to Excel-DNA
Hi,

I am new to both the .net and excel-dna, so I am trying to understand how I would re-design my Add-in into the excel-dna approach.

My Add-in (VBA), is actually a Class server. The user specifies what they want and the Add-in provides the class instances. e.g. Time Class, Public Holiday class.

Is there a way to segment the functions in the excel-dna, so the the user could type for example timedates.IsTime(). Or is the excel-dna addin just a lot of functions in one place?

Regards

Anthony

Govert van Drimmelen

unread,
Aug 1, 2021, 5:21:53 PM8/1/21
to exce...@googlegroups.com

Hi Anthony,

 

The functions you expose from an Excel-DNA add-in can  have any valid Excel name – this means you can have some extra characters like “.” or “?” in the name, which normally can’t be part of the method name in C# or VB.NET. You specify the name to register a method with using an attribute in your code if you want to override the default, which just uses the method name. It might look like this in C# or VB.NET respectively:

 

[ExcelFunction(Name="TimeDates.IsTime")]

public static bool IsTime()

{

}

 

<ExcelFunction(Name:= "TimeDates.IsTime")>

Public Shared Function IsTime() As Boolean

End Function

 

You can also specify the Excel function wizard category for your function:

[ExcelFunction(Name="TimeDates.IsTime", Category="Anthony’s Functions")]

 

How you arrange these functions inside your code is a separate issue to how they are registered with Excel.

So your functions can be in a various classes (or Modules in VB.NET) if that helps you to arrange them better, but that does not affect how they will be used in a formula.

They must just be public static (Public Shared) methods in a public class (or in a Public Module).

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/ea9f668f-fc65-4a52-ad33-b425ca84f771n%40googlegroups.com.

Anthony Taylor

unread,
Aug 2, 2021, 2:16:05 AM8/2/21
to Excel-DNA
Thank you for the quick information / feedback. This has given me food for thought....
Reply all
Reply to author
Forward
0 new messages