home *** CD-ROM | disk | FTP | other *** search
/ Computer Based Training: …, Windows 95 & NT Basics / a1454501.iso / msope / PE01.TXT < prev    next >
Encoding:
Text File  |  1997-02-24  |  6.3 KB  |  124 lines

  1. You can automate repetitive tasks in Excel by using ^Rmacros^r.
  2. |
  3. A macro is a series of commands and functions stored on a VBA (Visual Basic for Applications) sheet called a ^Rmodule^r.
  4. |
  5. You can run a macro whenever you need to carry out a task performed by that macro.
  6. |
  7. Before you record a macro, you should plan the steps and commands you want the macro to perform.
  8. |
  9. This is because any mistakes and corrections you make while recording a macro will be stored as steps in the macro.
  10. |
  11. To begin recording a macro, you choose ^UMacro - Record New Macro^u from the ^UTools^u menu.
  12. |
  13. This opens the Record Macro dialog box.
  14. |
  15. You can type a name for the macro at the first field (or you can accept the name suggested by Excel).
  16. |
  17. The first character of a macro name must be a letter. Other characters can be letters, numbers, or underscores. Spaces are not allowed in a macro name.
  18. |
  19. You have the option of creating a shortcut key for the macro by typing a letter at the appropriate field.
  20. |
  21. You can use an uppercase letter as a shortcut key by pressing ^RShift^r and entering a letter at the Shortcut key field.
  22. The shortcut key will override any default Excel shortcut keys while the workbook that contains the macro is open.
  23. |
  24. Excel inserts a default description for the macro, which you can change if you wish to.
  25. |
  26. A drop-down list allows you to choose where to store the macro.
  27. |
  28. All workbooks have access to macros stored in your Personal Macro Workbook.
  29. |
  30. Your Personal Macro Workbook (PERSONAL.XLS) is stored in the Startup folder (\XLSTART) of Excel. It is opened each time Excel is opened.
  31. If you are working on a network, your Personal Macro Workbook probably won't be available to others. In that case you should make sure that all required macros are located in each workbook.
  32. |
  33. You now click ^UOK^u, or press ^UEnter^u, to begin recording your macro.
  34. |
  35. The word "Recording" at the bottom of your screen indicates that any steps you now make will be recorded in the macro.
  36. |
  37. By default, absolute references are recorded for any cells you select while recording the macro.
  38. |
  39. However, if you click the ^URelative^u ^UReference^u button on the Stop Recording toolbar, relative references will be recorded for any cells you select while recording the macro.
  40. |
  41. When you run a macro recorded with absolute references, it will be executed in exactly the same cells as were recorded. However, macros recorded with relative references are portable throughout the workbook.
  42. |
  43. The ^URelative Reference^u button is now depressed, and you can carry out the steps you wish to record.
  44. |
  45. Say, for example, you want to create a macro to insert the name and address of Centurion Technologies Inc., relative to the active cell.
  46. |
  47. First you choose the font size for the company's name.
  48. |
  49. Next you click both the ^UBold^u and ^UItalic^u buttons on the Formatting toolbar.
  50. |
  51. Now you can type ^RCenturion Technologies Inc.^r, then press ^UEnter^u to select cell A2 before typing the company's address.
  52. |
  53. Once you have completed the steps you require, you click the ^UStop Recording^u button to finish recording the macro.
  54. |
  55. The macro has now been recorded and is stored in your Personal Macro Workbook.
  56. |
  57. Notice that the word "Recording" is no longer visible at the bottom of your screen.
  58. @@
  59. Suppose you want to try running your new macro on Sheet2 in your open workbook.
  60. |
  61. Since you recorded the macro named Centurion with relative references, you can choose the active cell to be a cell other than cell A1.
  62. |
  63. If you had recorded the macro with absolute references, you would only be able to run the macro correctly from cell A1 - the active cell when you began recording the macro - on the current sheet.
  64. |
  65. To run a macro that you have created you choose ^UTools - Macro - Macros^u, or press ^UAlt+F8^u.
  66. |
  67. The Macro dialog box lists the names of the macros available in All Open Workbooks, This Workbook, or PERSONAL.XLS - in this case All Open Workbooks is chosen.
  68. |
  69. The ^UOptions^u button allows you to change the description of the selected macro, or the shortcut key assigned to it.
  70. |
  71. You can remove a macro from the list by selecting it and clicking the ^UDelete^u button.
  72. |
  73. Your Personal Macro Workbook is normally hidden. So if you try to delete a macro from PERSONAL.XLS, you may be prompted to unhide the workbook before you can do so.
  74. You can display any hidden workbook using the ^UUnhide^u option in the ^UWindow^u menu.
  75. |
  76. To run the macro you click the ^URun^u button, or press ^UEnter^u.
  77. |
  78. The macro has now been executed (in this case relative to the chosen active cell, B3).
  79. @@
  80. @@
  81. @@
  82. You can edit, or write, macros attached to Excel workbooks using the Visual Basic (VB) Editor.
  83. |
  84. So you should be familiar with the VB Editor in order to do this.
  85. |
  86. For more information see the CBT Systems suite of Visual Basic 4.0 courses.
  87. |
  88. Suppose you record a macro called Months in the current workbook.
  89. |
  90. You do this by typing ^RJanuary^r in cell B3, and then filling right to cell D3.
  91. |
  92. You then select cell E3 before clicking the ^UStop Recording^u button.
  93. |
  94. Suppose you now wish to edit the macro so that it inserts labels for the months April, May, and June in cells B3 to D3, before selecting E3.
  95. |
  96. To edit a macro you choose ^UTools -^u ^UMacro - Macros^u, or press ^UAlt+F8^u.
  97. |
  98. You click ^UEdit^u to make changes to the macro selected from the list.
  99. |
  100. The ^UStep Into^u button in the Macro dialog box provides a debugging facility for the selected macro.
  101. |
  102. This opens the Visual Basic Editor, which shows the VB code for the macro named Months.
  103. |
  104. You can use ^UAlt+F11^u to toggle between Excel and the VB Editor.
  105.  
  106. This is equivalent to
  107.  
  108. ò choosing ^UTools - Macro - Visual Basic Editor^u
  109.   from Excel
  110.  
  111. ò choosing ^UView - Microsoft Excel^u from
  112.   Microsoft Visual Basic
  113. |
  114. You can now replace the word "January" with the word "April".
  115. |
  116. You can run the macro from the VB module by clicking the ^URun Sub/UserForm^u button.
  117. |
  118. This is the same as choosing ^URun Sub/UserForm^u from the ^URun^u menu, or pressing ^UF5^u.
  119. |
  120. If you choose to run a macro from the VB module, you should first ensure that the active cell is positioned appropriately in the Excel workbook.
  121. |
  122. To close the VB Editor and return to your Excel workbook, you choose ^UFile - Close and Return to Microsoft^u ^UExcel^u.
  123. @@
  124.