Getting Started
There are three possible ways of calling your C code from Microsoft Excel:
- From a Visual Basic module. You write a custom function in C and use the Declare statement to reference the function in the Visual Basic module. For more information about using DLLs with Visual Basic, see Chapter 5, "Using DLLs from Visual Basic."
- From a worksheet. You write a user-defined function in C, which Microsoft Excel users can enter on worksheets and evaluate. Your code is called whenever Microsoft Excel needs to calculate that function.
- From a menu, button, ON function, shortcut key, or toolbar. You write a custom procedure in C, which can be attached to a menu item, to a tool on the toolbar, to an event with an ON function, to a shortcut key, or to a button or other object on the worksheet drawing layer.
There is a difference between user-defined functions, which simply compute values based on their parameters and return the values, and user-defined commands, which actually perform actions. The following section describes calling DLLs from Microsoft Excel. For information on calling Microsoft Excel from your add-ins, see "Calling Microsoft Excel from C" on page 150.
Note
Writing DLLs is slightly more complex than writing normal Windows code, which in turn is more complex than writing normal C programs. Make sure you understand both before you begin.