Calling DNA fn from VBA

16 views
Skip to first unread message

John Lonergan

unread,
Nov 23, 2009, 6:12:19 AM11/23/09
to ExcelDna
Having problems calling dna worksheet function from VBA.
Does anyone have a trivial working sample?
In my case I have a no-arg volatile fn that returns a double..
double func();
which works ok when dropped into a sheet but I when called from VBA I
get a long integer value back and not the value returned from the
func. Possibly the long int value is one of the excel error numbers -
not sure.

In anycase someone else's working code would be helpful.

Thanks in advance.
John

Govert van Drimmelen

unread,
Nov 23, 2009, 6:37:08 AM11/23/09
to ExcelDna
Hi John,

It works fine for me with ExcelDna 0.20 and Excel 2007.

I have the following .dna file:

<DnaLibrary Language="C#">
using System;
using ExcelDna.Integration;

public class TestFunctions
{
static Random rnd = new Random();

[ExcelFunction(Description = "Random value greater than or equal
to 0 and less than 1.", IsVolatile = true)]
public static double NewRandom()
{
return rnd.NextDouble();
}
}
</DnaLibrary>

and the VBA function looks like this:
Function VbaNewRandom()
VbaNewRandom = Application.Run("NewRandom")
End Function

I can put =NewRandom() or =VbaNewRandom() in a sheet, and I get the
expected results.

Let us know if you find something interesting.

Regards,
Govert
Reply all
Reply to author
Forward
0 new messages