Looking Up Names

In the XLM macro language, you can find out what names refer to simply by invoking them. The only way to do this from a DLL is to call the function xlfEvaluate, which is the equivalent of the XLM macro language function EVALUATE. In the macro language, EVALUATE is not very useful because things are evaluated automatically anyway. However, from C, xlfEvaluate is quite useful.

The xlfEvaluate function takes any string containing a valid Microsoft Excel expression (anything that could be typed into a worksheet cell) and evaluates it using the standard Microsoft Excel evaluator. For example:

XLOPER x1, x2;

/* Evaluate the string "15+17" */
x1.xltype = xltypeStr;
x1.val.str = "\005" "15+17";

Excel4(xlfEvaluate, &x2, 1, (LPXLOPER) &x1);

/* x2 now contains 32 */

Although you can theoretically evaluate any expression, remember that the string you pass has to be parsed, which is a slow process. So if speed is important, avoid using xlfEvaluate.

Note

Calling xlfEvaluate is equivalent to pressing F9 in the formula bar. It cannot evaluate external references to sheets that are not open.

The xlfEvaluate function is most commonly used to look up the values assigned to names in a sheet. For example:

XLOPER x1, x2;

/* Look up the defined name "profits" on the active sheet */
x1.xltype = xltypeStr;
x1.val.str = "\010!profits";

Excel4(xlfEvaluate, &x2, 1, (LPXLOPER) &x1);
Excel4(xlFree, 0, 1, (LPXLOPER) &x2);

/* x2 now contains the definition of "profits" */

Note that xlfEvaluate cannot evaluate command equivalents, because they cannot be entered into cells on worksheets.