Monday 19 November 2012

Microsoft Excel 2007: Automating Excel with Macros (Win)

Automating Excel with Macros


A macro is a shortcut for performing a series of actions in an Excel worksheet. Macros are useful for automating complex or repetitive tasks, especially if the work is being shared, because it is easier to explain one step (i.e., activate the macro) than it is to explain several steps. Once a macro is created, you can activate it by using the Macro dialog box or by pressing a keyboard combination.



Creating & Recording a New Macro

  1. From the Developer command tab, in the Code group, click RECORD MACRORecord Macro button
    The Record Macro dialog box appears.
    Record Macro dialog box
  2. In the Macro name text box, type a name for the new macro
    NOTE: A macro name must begin with a letter and contain no spaces or special characters. Underscores ( _ ) are permissible.
  3. OPTIONAL: In the Shortcut key text box, type a letter that will be used to activate the macro
    NOTES:The shortcut key must be either an uppercase or lowercase letter.
    Macro shortcut keys will override any existing shortcuts while the workbook with the macro is open (e.g., copying with [Ctrl] + [C], underlining with [Ctrl] + [U]).
  4. To save the macro to the workbook that is currently open, from the Store macro in pull-down list, select This Workbook
    To save the macro to a new workbook, from the Store macro in pull-down list, select New WorkbookTo save the macro to Excel for use in any workbook, from the Store macro in pull-down list, select Personal Macro Workbook
  5. OPTIONAL: In the Description text box, type a summary of the macro's function or any other information
  6. Click OK
    The Record Macro dialog box closes and the macro begins recording.
  7. Perform the exact series of commands you want the macro to accomplish
  8. When finished, from the Developer command tab, in the Code group, click STOP RECORDINGStop Recording button
    The recording stops and the macro is saved.

Running a Macro

You can run a macro only after it has been created and recorded. Once you have chosen to run a macro, the macro will complete its commands until finished or until you suspend the macro.
WARNING: You should save your workbook before running a macro. If the macro's results are undesirable, you can close the workbook without saving and then reopen it, preserving the state of your workbook before using the macro.

Running a Macro: Ribbon Option

  1. OPTIONAL: If the insertion point is critical, set it in the appropriate location
    NOTE: This step will be useful if the macro's commands require you to begin in a specific cell.
  2. From the Developer command tab, in the Code group, click MACROSMacros button
    The Macro dialog box appears.
    Macro dialog box
  3. From the Macro name scroll box, select the macro you want to run
  1. Click RUN
    The Macro dialog box closes and the selected macro performs the steps it recorded.

Running a Macro: Keyboard Option

If a macro was given a keyboard shortcut when creating it, you can use the shortcut to run the macro.
  1. OPTIONAL: If the insertion point is critical, set it in the appropriate location
    NOTE: This step will be useful if the macro's commands require you to begin in a specific cell.
  2. Press the appropriate keyboard combination
    The macro runs.

Suspending & Resuming a Macro

If you need to, you can suspend (i.e., stop or pause) a macro's progress after you have chosen to run it.
  1. After you have started a macro, press [Esc]
    The macro is suspended.
  2. To complete the macro, run it
    The macro resumes where it was suspended.

Deleting a Macro

If you no longer need a macro, you can delete it. Once a macro has been deleted, it is no longer available in any workbook; however, changes that have already been made by the macro will not be undone.
  1. From the Developer command tab, in the Code group, click MACROSMacros button
    The Macro dialog box appears.
  2. From the Macro name scroll box, select the macro you want to delete
  3. Click DELETE
    A confirmation dialog box appears.
  4. To confirm the deletion, click YES
    The macro is deleted and the Macro dialog box closes.
  5. To delete more macros, repeat steps 1–4


Make sure to let me know in the comments below or on our Facebook page how you've got with it or Do you have any questions

No comments:

Post a Comment