Linux Application Development For The Enterprise (Charles River Media Programming)

3.4 Executing Macros

It has already been mentioned that you can easily call up the macro in whose code the cursor is located via F5 . However, this way of executing a macro is available only in the development environment. In general, one uses the command TOOLSMACRO, which is available both in Excel and in the development environment. With it you can run parameterless macros defined in any currently open file.

There are also a number of elegant methods for running macros:

These methods hold for procedural macros, those introduced with the keyword Sub , which we shall call subprograms. Function macros (keyword Function ) are, on the other hand, not designed to be called directly. They can be placed within other macros or inserted as calculating functions in the formula of a worksheet cell .

Interrupting Macros

All macros can be stopped at any time with Ctrl+Break . If you then select the button Debug in the form that appears after you hit Ctrl+Break , you can edit the code. You can also examine individual variables and then continue execution of the macro with F5 .

The Immediate Window

The immediate window is an aid for testing new procedures and for debugging. (In earlier versions the immediate window was called the test window.) The instruction Debug.Print places output in the immediate window, which is activated via ViewImmediate Window or with Ctrl+G .

The immediate window contains the last two hundred outputs implemented by Debug.Print . In the immediate window you can input instructions that are executed immediately when Return is pressed. The immediate window is particularly useful for testing variables or properties, for example by instructions such as ?varname or ?Application.ActiveSheet. Name (outputs the name of the active worksheet). The question mark is an abbreviation for the Print method. Floating point numbers are generally displayed in the immediate window to at most eight places beyond the decimal point, even when sixteen places exist.

In the immediate window it is also possible to assign values to variables or properties or to start macros by giving their name. In the immediate window you can introduce new variables without a previous declaration (even if Option Explicit is in force in the program code).

Tip  

The watch window makes possible the continuous display of the contents of various properties or variables. The use of this window will be described extensively in Chapter 6, where debugging is discussed. There we will also describe the window for the display of all active procedures.

Категории