Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xlfGetCell usage

398 views
Skip to first unread message

Ai

unread,
May 13, 2010, 5:48:01 AM5/13/10
to
Hi guys, new to excel development here. Any idea what is wrong with
the following piece of code?

XLOPER xRet, xArg, xRef;

xRef.xltype = xltypeSRef;
xRef.val.sref.count = 1;
xRef.val.sref.ref.rwFirst = 1;
xRef.val.sref.ref.rwLast = 1;
xRef.val.sref.ref.colFirst = 1;
xRef.val.sref.ref.colLast = 1;

xArg.xltype = xltypeInt;
xArg.val.w = 5; //value

Excel4(xlfGetCell, &xRet, 2, &xArg, &xRef);
return xRet.val.str;

In my worksheet, Row 1 Column A contains some value "a" but when I
call my UDF, "=Test()", which contain the above logic, it crashes
Excel. Please advise.

lab27

unread,
May 13, 2010, 11:14:29 AM5/13/10
to
Inline.

(If you're posting a registered function, it's useful to post the type
string you used to register it, and the prototype.)

Have you examined xRet? I suspect it will be an error, as it looks
like you're calling this from a worksheet. xlfGetCell is accessible
from commands, and macro sheet functions. Have a read of
http://msdn.microsoft.com/en-us/library/bb687835.aspx - specifically
the bit about Different types of functions, and what they can call.

Don't just access fields of a union without checking the discriminator
first. (xltype).

I went into this in a previous reply :
http://groups.google.co.uk/group/microsoft.public.excel.sdk/browse_thread/thread/6f92790ecb82d295

Rgds,

Lee.

0 new messages