I had an issue when I was making a simple UDF in C# with ExcelDna
The function uses this:
var reference = XlCall.Excel(XlCall.xlfCaller);
string oldValue = ((ExcelReference)reference).GetValue().ToString();
It would cause circular reference error (GetValue
tries to re evaluate the cell by calling the UDF again) unless I specified IsMacroType=true
, which marks the function as class 2 (add #
to a formula).
I have no idea how it would connect to circular error. But I guess ExcelReference.GetValue()
sometimes would evaluate the cell, sometimes not?
It seems class 2 only affect xlfCaller
,
And later I checked the source code for ExcelReference
, it turns out that it is actually xlCoerce that is called.
Also, I noticed when I press F2 on a cell, GetValue()
returns 0 no matter what the cell is. And when I press Ctrl+Alt+F9 force recalculate all, GetValue()
returns the previous calculated value.
Could someone elaborate me on this a little further? How does xlCoerce work on Cell value/formula anyway and how would class 2 affect it?