This function calls an internal Microsoft Excel macro function or special command from a DLL or code resource.
Returns one of the following (int).
Value |
Return code |
Description | |
0 |
xlretSuccess |
The function was called successfully. This does not mean that the function did not return a Microsoft Excel error value; to find that out, you have to look at the resulting XLOPER. | |
1 |
xlretAbort |
An abort occurred (internal abort). You might get this if a macro closes its own macro sheet by calling CLOSE, or if Microsoft Excel is out of memory. In this case you must exit immediately. The DLL can call only xlFree before it exits. The user will be able to save any work interactively using the Save command on the File menu. | |
2 |
xlretInvXlfn |
An invalid function number was supplied. If you are using constants from XLCALL.H, this shouldn't happen. | |
4 |
xlretInvCount |
An invalid number of arguments was entered. Remember that no Microsoft Excel function can take more than 30 arguments, and some require a fixed number of arguments. | |
8 |
xlretInvXloper |
An invalid XLOPER structure or an argument of the wrong type was used. | |
16 |
xlretStackOvfl |
(Windows only) A stack overflow occurred. Use xlStack to monitor the amount of room left on the stack. Don't allocate large local (automatic) arrays on the stack if possible; make them static. (Note that a stack overflow may occur without being detected.) | |
32 |
xlretFailed |
A command-equivalent function failed. This is equivalent to a macro command displaying the macro error alert dialog box. | |
64 |
xlretUncalced |
An attempt was made to dereference a cell that has not been calculated yet, because it was scheduled to be recalculated after the current cell. In this case the DLL needs to exit immediately. It can call only xlFree before it exits. For more information, see "Dealing with Uncalculated Cells" on page 196. |
Excel4(int iFunction, LPXLOPER pxRes, int iCount,
LPXLOPER argument1, ...)
iFunction (int)
A number indicating the command, function, or special function you want to call. For a list of valid iFunction values, see the following "Remarks" section.
pxRes (LPXLOPER)
A pointer to an allocated XLOPER (10 bytes) that will hold the result of the evaluated function.
iCount (int)
The number of arguments that will be passed to the function.
argument1, ... (LPXLOPER)
The optional arguments to the function. All arguments must be pointers to XLOPERs.
Valid iFunction values are any of the xlf... or xlc... constants defined in XLCALL.H or any of the following special functions:
xlAbort |
xlEnableXLMsgs |
xlGetInst |
xlSheetNm |
xlCoerce |
xlFree |
xlSet |
xlStack |
xlDefineBinaryName |
xlGetBinaryName |
xlSheetId |
xlUDF |
xlDisableXLMsgs |
xlGetHwnd |
Excel4 distinguishes between three classes of functions. The functions are classified according to the three states in which Microsoft Excel may be calling the DLL. Class 1 applies when the DLL is called from a worksheet as a result of recalculation. Class 2 applies when the DLL is called from within a function macro or from a worksheet where it was registered with a number sign (#) in the type text. Class 3 applies when a DLL is called from an object, macro, menu, toolbar, shortcut key, ExecuteExcel4Macro, or the Tools/Macro/Run command. The following table shows what functions are valid in each class.
Class 1 |
Class 2 |
Class 3 |
Any worksheet function Any xl... function except xlSet XlfCaller |
Any worksheet function Any xl... function except xlSet Macro sheet functions that return a value but perform no action |
Any function, including xlSet and command-equivalent functions |
If a command-equivalent function has an associated dialog box, you can set the xlPrompt bit in iFunction. This means that Microsoft Excel will display the appropriate dialog box before carrying out the command.
If you set the xlIntl bit in iFunction, the function or command will be carried out as if it were being called from an International Macro Sheet. This means that the command will behave as it would on the U.S. version of Microsoft Excel, even if it is running on an international (localized) version.
After receiving one of these return values, your DLL needs to clean up and exit immediately. Callbacks into Microsoft Excel, except xlFree, are disabled after receiving one of these return values.
This example uses the Excel4 function to select the cell from which it was called.
\SAMPLES\EXAMPLE\EXAMPLE.C
short WINAPI Excel4Example(void)
{
XLOPER xRes;
Excel4(xlfCaller, (LPXLOPER)&xRes, 0);
Excel4(xlcSelect, 0, 1, (LPXLOPER)&xRes);
Excel4(xlFree, 0, 1, (LPXLOPER)&xRes);
return 1;
}
Excel4v, Excel