Hi Paolo,
The simplest way to call your Excel-DNA user-defined functions or
macros from VBA is to use Application.Run.
For this, at least the following types work, maybe a few more.
String
Double
Integer
Date (careful - passed as string?)
Variant (with nothing strange inside - only string, double etc)
Array of Double
Array of String (though Excel-DNA does not allow string array type to
be used as a parameter, so you need to define it as object array
in .NET)
Array of Variant (object array in .NET)
Collections won't work - you should convert to arrays.
There is no difference in this respect between
VB.NET and C#, it has
to do with the data types that the Excel C API supports. Excel does
not know how to convert your VBA Collection class into a type it can
pass along with the C API.
--------
Another, more advanced, approach to integrating VBA and your Excel-DNA
add-in is to make a COM Server which you can use from VBA. In this
case the integration and rules would be completely different, since we
are using the .NET/COM integration instead of the Excel C API for
linking VBA and .NET. I would not suggest you start with this, but
it's good to know there is another integration option too.
Regards,
Govert
On Feb 22, 11:22 pm, Forna <
paolo.fornar...@gmail.com> wrote:
> I have been reading in the forum about passing variables from Excel
> VBA to an Excel DNA C# function.
> I would just like to get a confirmation on the passable types...
>
> - basic types (string, integer...) and two-dimensional arrays can be
> passed fine;
>
> - collections cannot be passed from VBA to C# since there is no
> equivalent as a VBA collection in C# (but they may be passed from VBA
> to VB.Net).
>
> Can you confirm this is correct?
>
> Thank you
>
> On Feb 12, 5:22 pm, Govert van Drimmelen <
gov...@icon.co.za> wrote:
>
>
>
>
>
>
>
> > Hi Paolo,
>
> > All the options you mention are viable.
>
> > I suggest
> > 1. Try to port your VBA code to
VB.NET, maybe looking at the
> > discussions and document here:
http://sysmod.wordpress.comandth
> > recent discussions with Patrick O'Beirne on this newsgroup. With some
> > small changes (e.g. ThisWorkbook doesn't exist, but you might look at
> > ActiveWorkbook) you should be able to get your existing plan working
> > in
VB.NET. That might be a good start.
> > 2. Have a look at the FinAnSu example (a slightly older but leaner
> > example here:
http://code.google.com/p/finansu/andthe current