A word in advance: when you open the macros you recorded in the VBA Editor, you will probably not fully understand what you see. You will need to read the tutorial sections on Objects and their Members in order the interpret the macro code.
There are several areas in the VBA Editor, but for our purposes we will deal with just two: the "Project Explorer," which is the area in the upper left, and the "Code Window," which is the main area to the right. If you open the VBA Editor by editing a macro, the macro will be open in the Code Window. If you open the VBA Editor by starting the program, what appears in the code area when the Editor program starts depends on which workbooks are open, whether they contain macros, and other factors.
The Project Explorer lists all open workbooks in a tree view. In the VBA Editor these are referred to as "projects." Each project has several parts, which you can see if you expand the project.
Each macro in a module starts with the word "Sub" (for subroutine), and the macro name, followed by a pair of parentheses. The macro commands, or "code," follows. The macro ends with the phrase "End Sub." The VBA Editor automatically inserts a separating horizontal line between the macros in a module.
To look at the macro code of the macros you recorded in Chapter 3, start the VBA Editor, then navigate to the Personal Macro Workbook (personal.xls or personal.xlsb) in the Project Explorer. Make sure "Modules" under that project is expanded. There maybe be one or several modules. Double-click on each module until you open the module that contains the macros you recorded. (You may need to scroll down in the Code Window to see which macros are in each module). The code for the macros will appear in the Code Window.
A macro actually consists of only the macro commands (and optionally VBA language statements). Inserting formatting such as tabs, indentation, and blank lines into the macro code while you edit it will format the visual presentation of the macro when it is opened for editing. However, this formatting will have no effect when the macro is run. Extra spaces will also be ignored, except where they are part of text enclosed in quotation marks.
You can type, delete, move and copy text in the macro code, as you would in any document. Commands that you insert in the macro when editing or programming must be in the exact form required by the macro language, otherwise the commands will not be recognized and you will get an error. VBA macros are not "case-sensitive." This means that for commands and variable names, upper- and lower-case characters are considered identical. The VBA Editor likes to see the macro commands and VBA language statements (covered later in the tutorial) in initial caps, and will automatically change them if they are typed in a different case configuration.
To compile a macro, click on Debug/Compile. If there is a problem you will get an error message. There is no indication when the macro compiles successfully (no news is good news), so if you do not get an error message that means the macro has compiled successfully.
It is useful to include comments in your macro: you might want to explain how it works, what its purpose is, call attention to certain features, etc. Comments are a great help when editing a complex macro, particularly one that was programmed some time ago or by someone else. Macro code whose purpose and method seem obvious at the time when the macro was originally written can be bewildering when looked at later. Comments appear as text within the macro when the macro is edited, but they are ignored when the macro is compiled and have no effect when the macro is run.
To insert comments in a macro, precede the comment text with an apostrophe (" ' "). When the macro is compiled everything from the apostrophe to the end of the line will be ignored. On multi-line comments, each line must start with an apostrophe.