xlfEvaluate

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Uses the Microsoft Office Excel parser and function evaluator to evaluate any expression that could be entered in a worksheet cell.

Excel12(xlfEvaluate, LPXLOPER12 pxRes, 1, LPXLOPER12 pxFormulaText);

Parameters

pxFormulaText (xltypeStr)

The string to be evaluated. A leading equal sign (=) is optional. The string can be any text that can legally be entered into a worksheet or macro sheet cell.

Property Value/Return Value

Returns the result of evaluating the string which can be any of the types xltypeNum, xltypeStr, xltypeBool, xltypeErr, xltypeNil, xltypeMulti.

Remarks

The string can contain only functions, not command equivalents. It is equivalent to pressing F9 from the formula bar. If xlfEvaluate is called from an XLL worksheet function that has been registered as thread safe, the expression must only contain thread-safe functions.

The primary use of the xlfEvaluate function is to allow DLLs to find out the value assigned to a defined name that is either on a sheet or a hidden name defined within the DLL. Note that within a DLL/XLL, a worksheet name must be prefixed with at least an exclamation mark (!) to ensure that it is interpreted as external to the DLL. For more information, see Evaluating Names and Other Worksheet Formula Expressions.

xlfEvaluate cannot be used to evaluate references to an external sheet that is not open.

Example

This example uses xlfEvaluate to coerce the text "!B38" to the contents of cell B38.

\SAMPLES\EXAMPLE\EXAMPLE.C. This function calls a command macro (xlcAlert) and will work correctly only when called from a macro sheet or as a macro command.

short WINAPI EvaluateExample(void)
{
    XLOPER12 xFormulaText, xRes, xRes2, xInt;

    xFormulaText.xltype = xltypeStr;
    xFormulaText.val.str = L"\004!B38";
    Excel12(xlfEvaluate, &xRes, 1, (LPXLOPER12)&xFormulaText);

    xInt.xltype = xltypeInt;
    xInt.val.w = 2;
    Excel12(xlcAlert, &xRes2, 2, (LPXLOPER12)&xRes, (LPXLOPER12)&xInt);
    Excel12(xlFree, 0, 1, (LPXLOPER12)&xRes);
    Excel12(xlFree, 0, 1, (LPXLOPER12)&xRes2);

    return 1;
}

See Also

Concepts

Essential and Useful C API XLM Functions