Thomas Horstmann
Posts: 12
Joined: 2020-08-24
|
I have got an Excel UDF. Is there a way to locate the cell which sends/calls the function, when I calculate it? |
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
Joined: 2004-04-05
|
Hi Thomas,
The Excel Object Model has the Caller property:
https://docs.microsoft.com/en-us/office/vba/api/excel.application.caller
Please see below a small code sample below:
function TADX_XLFunction.MyFunc(const param0, param1, param2: OleVariant): OleVariant;
var
caller: OleVariant;
rng: ExcelRange;
addr: WideString;
begin
caller := Self.COMAddInModule.ExcelApp.Caller[EmptyParam, adxLCID];
if Not VarIsError(caller) then begin
if (TVarData(caller).VType = varDispatch) then begin
rng := IDispatch(TVarData(caller).VDispatch) as ExcelRange;
addr := '+++ ' + rng.Address[true, true, xlA1, false, false];
OutputDebugString(PWideChar(addr));
end;
end;
...
|
|