XLL+ Class Library

CXlOper::GetCaller

Retrieve a reference to the cell or cells that called the add-in function

[C++]
int GetCaller(
   BOOL bFullRef
);

Parameters

bFullRef

If bFullRef is FALSE (the default value), then only a local reference will be placed in the CXlOper. This will be of type xltypeSRef, and will not contain a sheet ID. If bFullRef is TRUE, then an absolute reference will be retrieved. This will be of type xltypeRef, and will contain a sheet ID.

Return value

The result of the SDK call-back. xlretSuccess (0) indicates success. Other values indicate failure. A full list of return values can be found in the section "Return codes" in the MS SDK header file XLCALL32.H.

Remarks

GetCaller() tells you which cell (or cells) the add-in function was called from. It fills the CXlOper object with a reference to the cell or cells that called the add-in function.

If the current function was not called from a cell (or cells) then the object will not contain a reference. For example, the function may have been called from a button or a menu, or it may have been called by an event handler such as OnCalculate(). The table below shows the results of using GetCaller() in different situations.

Called from bFullRef Result type Result contents
Worksheet cell(s) FALSE xltypeSRef Local range reference, excluding sheet ID
Menu FALSE xltypeMulti Array of 4 numbers, as follows:
1 Index of item within menu
2 Index of menu in menu bar
3 Menu bar number (Excel application menu = 10)
4 0
Button FALSE xltypeStr String containing button name
Event handler FALSE xltypeErr xlerrRef
Worksheet cell(s) TRUE xltypeRef Absolute range reference, including sheet ID
Menu TRUE Function fails N/A
Button TRUE Function fails N/A
Event handler TRUE Function fails N/A

It is therefore advisable to check that the result is a reference, by calling CXlOper::IsRef, as in the following code:

CXlOper xloCaller;
if ((xloCaller.GetCaller() != 0) || !xloCaller.IsRef())
{
    // Fail
}

Example

CXlOper::GetCaller() Example

Requirements

Header: xllplus.h

See Also

CXlOper Class | CXlOper Methods | CXllApp::GetCallerDims() | CXlRef