Export (0) Print
Expand All

xlfEvaluate

Last modified: July 01, 2011

Applies to: Excel 2013 | Office 2013 | Visual Studio

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


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

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.

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

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.

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;
}
Show:
© 2015 Microsoft