Volunteer Software

People Helping People

Enclosed is a section of Microsoft’s help file in Excel 2007, verbatim, with the addition of some screen shots to illustrate the instructions. The process is straightforward and the rewards are a custom spreadsheet specific to your own organization’s needs—with a one-time setup and perpetual use. Customization is one of the virtues of sending reports to Microsoft Office formats. Use a macro when you want to go beyond the Reporter’s Do-It-Yourself spreadsheet design.

Excel 2007 Microsoft Help Topic

To automate a repetitive task, you can quickly record a *macro in Microsoft Office Excel. (You can also create a macro by using the **Visual Basic Editor in Microsoft Visual Basic to write your own macro script, or to copy all or part of a macro to a new macro.) After you create a macro, you can assign it to an object (such as a toolbar button, graphic, or control) so that you can run it by clicking the object. If you no longer use a macro, you can delete it.

Terms:
*macro: An action or a set of actions that you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.
**Visual Basic Editor: An environment in which you write new and edit existing Visual Basic for Applications code and procedures. The Visual Basic Editor contains a complete debugging toolset for finding syntax, run-time, and logic problems in your code.

Record a macro

When you record a macro, the macro recorder records all the steps required to complete the actions that you want your macro to perform. Navigation on the Ribbon is not included in the recorded steps. Fast forward to the steps to Record after the Developer tab is enabled.

  1. If the Developer tab is not available, do the following to display it:

Click the Microsoft Office Button, and then click Excel Options.

excel_macro01

2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

excel_macro02

3. Click OK.

  • To set the security level temporarily to enable all macros, do the following:
  • On the Developer tab, in the Code group, click Macro Security.

excel_macro03

4. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

excel_macro04

Note — To help prevent potentially dangerous code from running, we recommend that you return to any one of the settings that disable all macros after you finish working with macros. For more information about how to change the settings, see “Change macro security settings in Excel” in the Excel Help file. Click the question mark icon in Excel.

Steps to Record

On the Developer tab, in the Code group, click Record Macro.

excel_macro05

In the Macro name box, enter a name for the macro.

excel_macro06

 

  • Note — The first character of the macro name must be a letter. Subsequent characters can be letters, numbers, or underscore characters. Spaces cannot be used in a macro name; an underscore character works well as a word separator. If you use a macro name that is also a cell reference, you may get an error message that the macro name is not valid.
  • To assign a CTRL combination shortcut key to run the macro, in the Shortcut key box, type any lowercase letter or uppercase letter that you want to use.
    Note — The shortcut key* will override any equivalent default Excel shortcut key while the workbook that contains the macro is open. For a list of CTRL combination shortcut keys that are already assigned in Excel, see “Excel shortcut and function keys.”
    *Definition of shortcut key: — A function key or key combination, such as F5 or CTRL+A, that you use to carry out a menu command. In contrast, an access key is a key combination, such as ALT+F, that moves the focus to a menu, command, or control.
  • In the Store macro in list, select the workbook where you want to store the macro.
    Tip: — If you want a macro to be available whenever you use Excel, select Personal Macro Workbook. When you select Personal Macro Workbook, Excel creates a hidden personal macro workbook (Personal.xlsb) if it does not already exist, and saves the macro in this workbook.
    – In Windows Vista, this workbook is saved in the C:\Users\user name\AppData\Local\Microsoft\Excel\XLStart folder.
    – In Microsoft Windows XP, this workbook is saved in the C:\Documents and Settings\user name\Application Data\Microsoft\Excel\XLStart folder.
    – Workbooks in the XLStart folder are opened automatically whenever Excel starts.
    – If you want a macro in the personal macro workbook to be run automatically in another workbook, you must also save that workbook in the XLStart folder so that both workbooks are opened when Excel starts
  • In the Description box, type a description of the macro.
  • Click OK to start recording.
  • Perform the actions that you want to record.
  • On the Developer tab, in the Code group, click Stop Recording

excel_macro07

Tip: — You can also click Stop Recording on the left side of the status bar at the bottom of the screen.

excel_macro08

Run a macro by pressing a CTRL combination shortcut key.

Microsoft’s Help file offers more information on macros.

 

BACK TO TUTORIALS