xlUDF

Applies to: Excel 2013 | Office 2013 | Visual Studio

Calls a user-defined function (UDF). This function allows a DLL to call Visual Basic for Applications (VBA) user-defined functions, XLM macro language functions, and registered functions contained in other add-ins.

Excel12(xlUDF, LPXLOPER12 pxRes, int iCount, LPXLOPER12 pxFnRef,
LPXLOPER12 pxArg1, ...);

Parameters

pxFnRef (xltypeRef, xltypeSRef, xltypeStr or xltypeNum)

The reference of the function you want to call. This can be a macro sheet cell reference, the registered name of the function as a string, or the register ID of the function. For XLL add-in functions registered using xlfRegister or REGISTER with the argument pxFunctionText supplied, the ID can be obtained by using xlfEvaluate to look up the name.

pxArg1, ...

Zero or more arguments to the user-defined function. When you are calling this function in versions earlier than Excel 2007, the maximum number of additional arguments that can be passed is 29, which is 30 including pxFnRef. Starting in Excel 2007, this limit is raised to 254, which is 255 including pxFnRef.

Return value

Returns whatever value the user-defined function returned.

Example

The following example runs TestMacro on sheet Macro1 in BOOK1.XLS. Make sure that the macro is on a sheet named Macro1.

\SAMPLES\EXAMPLE\EXAMPLE.C

short WINAPI xlUDFExample(void)
{       
   XLOPER12 xMacroName, xMacroRef, xRes;
   xMacroName.xltype = xltypeStr;
   xMacroName.val.str = L"\044[BOOK1.XLSX]Macro1!TestMacro";
   Excel12(xlfEvaluate, &xMacroRef, 1, (LPXLOPER12)&xMacroName);
   Excel12(xlUDF, &xRes, 1, (LPXLOPER12)&xMacroRef);
   return 1;
}

See also