XLL+ Class Library

Macro functions

What are macro functions?

When an add-in function is specified as a worksheet function, it can (as the name implies!) be called from a cell in a worksheet. To comply with the requirements of Excel's recalculation, a worksheet function is forbidden to change values in workbooks or to do a number of other actions such as finding the active cell or worksheet.

A function that acts on a workbook, rather than just returning a value, is called a macro function. It can use the Excel SDK API to manipulate workbooks in a variety of ways, just like a VBA macro. However, a macro written in C++ differs from one written in VBA in two significant ways:

Calling a macro function

A macro function can be called in one of three ways:

  1. Through a GUI device, such as a menu or button. Macros called in this way cannot take any arguments.
  2. From VBA, using Application.ExecuteExcel4Macro(MacroName).
  3. After being installed as an event-handler.

Note that a macro function cannot be called from a worksheet cell, unless it is also specified to be a worksheet function.

Specifying a macro function

In the Function Wizard, you can specify that a function be a worksheet function, a macro function, or both, using the Worksheet and Macro check-boxes.

Next: Setting cell values >>