passing arrays to VB via EXCEL4 API

C

cell division

I've written what seems like pretty straight-forward code, bu
regardless of how much I simplify it, I can't get it to work. I'd lik
to build an XLOPER that represents an array ( type xltypeMulti) whic
contains some number of XLOPERs representing ints (type xltypeInt).
After that, I want to pass it via the xlUDF function to VB code.

Here's pretty much the entire block of interesting code which lives i
the xll:

XLOPER xelem[2];
XLOPER xArray;
XLOPER xFuncStr;
XLOPER xRet;
char funcName[20];

xelem[0].xltype = xelem[1].xltype = xltypeInt;
xelem[0].val.w = 1;
xelem[1].val.w = 2;

xArray.xltype = xltypeMulti;
xArray.val.array.lparray = (LPXLOPER) &(xelem[0]);
xArray.val.array.rows = 1;
xArray.val.array.columns = 2;

stctop("sendArrayToVB", funcName); // a convenience Cstr to Pst
function

xFuncStr.xltype = xltypeStr;
xFuncStr.val.str = funcName;

Excel4(xlUDF, (LPXLOPER)&xRet, 2, (LPXLOPER)&xFuncStr
(LPXLOPER)&xArray);

The UDF function returns an error of type xlerrValue. If I simplif
the argument I'm passing to my VB function (passing, say, xelem[0], a
XLOPER representing a simple integer value) everything works fine
which makes me believe that the problem has to do with passing th
xltypeMulti array to the VB layer.

If it matters, the VB function sendArrayToVB has the followin
signature:

Public Sub sendArrayToVB(pArr As Variant)

If anyone has any examples of this - creating a xltypeMulti array o
XLOPERs and passing it via xlUDF to a VB function, that would be a hug
help. Of course, anyone who can just look at this mess and figure ou
what's wrong, that would be equally fantastic.

Thanks in advance,

- Ro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top