cell reference in C-API xll

J

Janwillem van Dijk

I have a function compiled into an xll add-in using a pascal version of
the C-API for getting the formula in a cell as a string. It needs the
row and column index of a cell and works fine.

However, I would rather have a cell as parameter than its indices,
giving a function like:
function GetFormulaInCellXl(var CellXl: TXloper): PxlOper; stdcall;

However I do not succeed in getting this right for xlfGetCell. It always
returns #VALUE. (I can also manage it to crash excel)

Question: How do you get the row,col values of a cell that is parameter
to a function. (tips using C also welcome.)

The essential lines of the working version are below:

function GetFormulaXl(var RowXl, ColXl: TXloper): PxlOper; stdcall;
....
.... get row and col from XlOpers RowXl, ColXl
....
//Set reference
ref.xlType := xltypesref;
ref.val.sref.Count := 1;
with ref.val.sref.xlref do
begin
firstrow := Row;
firstcol := Col;
lastrow := Row;
lastcol := Col;
end;
tempInt.xlType := xlTypeInt;
tempInt.val.int := 6;
xlresult := _Excel4v(xlfGetCell, @ResultXlOper,
2, [@TempInt, @Ref]);
//Returns the formula in the default reference style
//xlfGetFormula would return R1C1 style
//_Excel4v is excel4v with "asm pop sink end;"
//for removing 4 bytes left by Excel4v function call
end;
result := @ResultXlOper;
....


It is registered with 'PPP#' as type

Thanks,
Janwillem
 
S

Stephen Bullen

Hi Janwillem,

Questions about Excel's C Api and xlls are generally answered in the
Public.Excel.sdk newsgroup. You might like to repost your question
there.

Regards

Stephen Bullen
Microsoft MVP - Excel
 

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