On 05/09/2012 02:39, HedgePig wrote:
> I wanted to add that if I use something like
> Application.Run("HelloWorld", mystring)
> then it seems that I cannot pass mystring by reference. This is also a
> "problem" in that ultimately, I want to call a VB function/subroutine
> that will pass back a lot of modified data.
Threads to follow on this liist:
17-May-2012 [ExcelDna] Re: COM, API, Interop and UDFs?
6-Aug-12 [ExcelDna] Re: ComServer examples
I had hoped I could use Smurf's suggestion on XLLs:
>
Using declares will get you your answer = func(...) style. Func will
be whatever you declare your xll function will be known as in VBA as in:
Declare Function theVBAName Lib "thexll.XLL" Alias "theXLLName" (ByVal
int as long) As Long
<
so I tried
Declare Function AddThem Lib "TestDna.XLL" Alias "f0" (ByVal int1 as
long, ByVal int2 as long) As Long
BUT Govert says
>>
In general the VBA Declare style access will not work. The Excel-DNA
functions return XLOPER data structures to Excel (that's what
the 'Q's
mean in the registration string), and dealing with these in VBA
would
be a nightmare. The fact that it nearly seems to work is a red
herring. For functions that take doubles and return a double you
might
be able to pull it off with the 'IsExceptionSafe:=True' option
set on
the .NET side. But there is no chance of passing strings or objects
around that way.
The COM Server support is the right direction to look if you really
need to use the .NET code from VBA.
Excel-DNA can interact with Excel in different ways. The most basic is
the UDF and macros which are registered through the C API. These only
allow simple types like double, string, and object arrays object[,]
that contain simple types. Kevin's pointer is a good one as a
reference for this. These functions can be called from the worksheet,
or from VBA using Application.Run.
Excel-DNA can also expose itself as a COM server to VBA. In this
respect, Excel-DNA does not really add any power - you can register
and use a regular .NET library via COM in VBA, and with Excel-DNA
getting everything working the first time is probably harder. The
advantage is that you have single add-in for worksheet UDFs and
objects exposed to VBA. The keyword to search for in this group to
find more about Excel-DNA's support for VBA interop is "ComServer":
https://groups.google.com/group/exceldna/search?group=exceldna&q=comserver&qt_g=Search+this+group.
<<