Setting a Function to Be Non-Volatile

653 views
Skip to first unread message

Chris Spicer

unread,
Jan 26, 2009, 7:24:40 AM1/26/09
to ExcelDna
Could anyone clarify the syntax for setting a function to be non-
volatile, within the function itself? I'm trying to use the
following:

[ExcelFunction(IsVolatile=true)]
public static object MyFunc()
{
XlCall.Excel(XlCall.xlfVolatile, 0);
return "OK";
}

... but is throws an XlCallException.

Thanks, Chris

Govert van Drimmelen

unread,
Jan 26, 2009, 7:47:03 AM1/26/09
to ExcelDna
Hi Chris,

The Excel xlfVolatile fucntion can only be used in macro sheet
equivalent (IsMacroType=true) functions. The following function will
not be volatile, and work as you expect:
[ExcelFunction(IsMacroType=true, IsVolatile=true)]
public static object MyFunc()
{
XlCall.Excel(XlCall.xlfVolatile, false);
return System.DateTime.Now;
}

Note that functions marked a macro-sheet equivalent (IsMacroType=true)
that have arguments allowing range references (AllowReference=true)
are volatile by default even if marked with (IsVolatile=false).

Regards,
Govert

Chris Spicer

unread,
Jan 26, 2009, 8:07:07 AM1/26/09
to ExcelDna
Thanks Govert, that did it.

I wasn't precisely clear on what a 'macro equivalent function' was,
but I found the following link clarified the term. Hopefully others
may find it useful.

http://msdn.microsoft.com/en-us/library/bb687832.aspx
> > Thanks, Chris- Hide quoted text -
>
> - Show quoted text -

Chris Spicer

unread,
Jan 26, 2009, 8:07:07 AM1/26/09
to ExcelDna
Thanks Govert, that did it.

I wasn't precisely clear on what a 'macro equivalent function' was,
but I found the following link clarified the term. Hopefully others
may find it useful.

http://msdn.microsoft.com/en-us/library/bb687832.aspx

On Jan 26, 12:47 pm, Govert van Drimmelen <gov...@icon.co.za> wrote:
Reply all
Reply to author
Forward
0 new messages