Previous section-----Next section

Creating a Macro

To call Mathematica code as an Excel macro, the Mathematica code must be contained in a named code box inside Excel. Once you have created the named code box, you can then create a button that will call the code in the box. The Mathematica Macros manager can help you do this.

To create a macro code box:

The Example macro is added to the list Available Macros and a code box for the Example macro is inserted at the location you specified.

Running Mathematica code as an Excel macro.

The initial contents of the code box are specified by a customizable template. In this case, you can leave the default code as is. Before running the code, however, you should type values into the cells referenced in the macro.

To run a macro:

To make it more convenient to run the macro, you can create a button for the macro.

To create a macro button:

Creating a button for a Mathematica macro.

Notes
• The default macro name, Initialization, is reserved for code you want to run automatically every time you connect to a kernel or click Evaluate.
• To move a button or a code box, hold down the Ctrl key before selecting it.
• Code boxes can be located anywhere in a workbook. They do not need to be on the same sheet as the button calling the code.