Quick Question - Is it possible to simply return the current cell value as the function result?

418 views
Skip to first unread message

Damon Wilder Carr

unread,
Jan 21, 2016, 3:53:16 PM1/21/16
to Excel-DNA


I have a case where I need to 'turn off' my UDF. When this occurs I simply want it to return whatever is now in the cell as the result of the UDF.

I've set the IsMacroType to true on the UDF - this at least lets me call GetValue() on the ExcelReference for the caller, however it always returns 0. Is there a way to get the previous result that is already in the cell and just return it as the new result?

For example, this code always returns 0 no matter what the value in the cell is before the call:

ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;



if (IsSuspended)

{

      return caller.GetValue();

}



Thanks,

Damon

Govert van Drimmelen

unread,
Jan 21, 2016, 4:38:04 PM1/21/16
to exce...@googlegroups.com
Hi Damon,

Your approach is right, with xlfCaller, and IsMacroType=true.
However, you can only get the current value of the cell if it is changed by a recalculation (e.g. if an input parameter changed), not if you enter the formula or edit it with F2.

-Govert



From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Damon Wilder Carr [damon...@gmail.com]
Sent: 21 January 2016 10:53 PM
To: Excel-DNA
Subject: [ExcelDna] Quick Question - Is it possible to simply return the current cell value as the function result?

--
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 post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages