UDF Doesn't Work When Called By xlfEvaluate

29 views
Skip to first unread message

Terry Aney

unread,
Aug 24, 2021, 2:13:56 PM8/24/21
to Excel-DNA
Hi,

I have the following function:

[ExcelFunction]
public static string BTRNumberFormat(
double value,
string format,
object culture = null
)
{
var cultureArg = OptionalValues.Check<string>( culture, nameof( culture ), "en-US" );
return Functions.Utility.LocaleFormat( value, format, cultureArg );
}

It just formats a number with a c# format string based on a culture passed in.

Everything is fine if I do something like the following:

XlCall.Excel( XlCall.xlfEvaluate, "=BTRNumberFormat(5,\"0.00\",\"en-US\" )")

However, if the UDF appears multiple times in the formula string, I get ExcelErrorName.  For example, the following does not work.

XlCall.Excel( XlCall.xlfEvaluate, "=BTRNumberFormat(5,\"0.00\",\"en-US\" ) & \" \" & BTRNumberFormat(5,\"0.00\",\"en-US\" )")

Any idea on what is going on?

Terry Aney

unread,
Aug 24, 2021, 2:17:44 PM8/24/21
to Excel-DNA
Also, it isn't isolated to using the 'same' UDF 2x, if I use more than one UDF in the formula, it returns ExcelErrorName.

Govert van Drimmelen

unread,
Aug 24, 2021, 2:53:56 PM8/24/21
to exce...@googlegroups.com

I can reproduce what you see, and the same issue was discussed here:

c# - ExcelDNA Evaluate Formula returns ExcelErrorName for custom UDF's - Stack Overflow

 

-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/0e2e6e37-41b1-436b-bf2c-b78c9d319200n%40googlegroups.com.

Terry Aney

unread,
Aug 24, 2021, 3:18:26 PM8/24/21
to Excel-DNA
Hmm, I went do the rabbit hole of those posts :)  Unfortunately, kb823604 doesn't seem to exist on the web anymore (for possible work arounds or anything) :(
Reply all
Reply to author
Forward
0 new messages