Page 56 - Microsoft Office Excel 2003 Programming Inside Out
P. 56

Microsoft Office Excel 2003 Programming Inside Out























                             Figure 3-7.  You can view the code behind a macro in the Visual Basic Editor.

                             This macro applies bold and italic formatting to the contents of the selected cell and to the
                             contents of cell H13. Another aspect of this particular macro is that it was supposed to work
                             for the active cell and the cell two columns to its right, but instead affects the active cell and
                             cell H13. The reason that happened for this macro is that the macro recorder was using absolute
             Chapter 3
                             references, which reflect the names of the cells selected during macro recording, instead of
                             relative references, which reflect the positions of the selected cells in relation to the active cell
                             when you start recording the macro. You can change your macro from absolute references to
                             relative references by clicking the Relative References button on the Stop Recording toolbar.
                             Figure 3-3 shows the same macro recorded using relative references.























                             Figure 3-8.  A more flexible macro that works on any set of cells, not just the cells selected
                             when the macro was recorded.



                30
             Part 2:  Visual Basic for Applications
   51   52   53   54   55   56   57   58   59   60   61