开发者

Excel UDF returns a huge number

开发者 https://www.devze.com 2023-03-19 05:44 出处:网络
Excel AddIn using Excel DNA, VS2008, C#, MyUDF(param1, parm2) when I type in \"=MyUDF\" and hit enter, Excel displays a huge number like 970063926

Excel AddIn using Excel DNA, VS2008, C#, MyUDF(param1, parm2) when I type in "=MyUDF" and hit enter, Excel displays a huge number like 970063926 and my c# code for MyUDF is not run

Anyone know what is this huge num开发者_运维技巧ber?

thanks


This is just a bit of weird behaviour of Excel. The number being returned is an internal identifier for the UDF function, and by entering the function name without any brackets, you're causing it to be treated like a named range not a function. If you want to call the function with no arguments, use:

=MyUDF()

...if you type =MyUDF then you're asking Excel to dereference the function name, in the same way that it would dereference =A1 to the value in cell A1 or =MyNamedRange to whatever that named range referred to.

I don't think there's any practical use for the behaviour you've observed, but it certainly isn't going anywhere near your code to get this value that is being returned, so don't worry you haven't done anything wrong!


Is there any way to avoid this behavior? If no parameter is specified, I would like the =MyUDF to return error instead a number.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号