![]() |
Leading the way in Microsoft Office Development |
| Home | | | Excel | | | Word | | | PowerPoint | | | Consultancy | | | Feedback | | | Contact |
| Microsoft Excel > Macros > Running a Macro | < Previous | Next > |
Step 1 - How can I run a Macro ? |
You can run macros that are either in the current workbook or in any other open workbook. | ||
Running a macro is very easy and there are several ways you can do this. | ||
1) Using the Macro dialog box. | ||
2) Using a Shortcut Key with a combination of holding down Ctrl. | ||
3) Using a graphic or AutoShape. | ||
4) Using a Button assigned to an existing toolbar or drop-down menu. |
Step 2 - Using the Macro dialog box |
You could run your macro from the Macro dialog box. Select (Tools > Macro > Macros). | ||
Select the name of your macro from the list and press the "Run" button. | ||
Alternatively you can use the shortcut key (Alt + F8) to display the Macro dialog box. |
![]() | (Tools > Macro > Macros) dialog box |
The default is to display all the macros that are currently available from "All Open Workbooks". | ||
It is possible to change the "Macros in" drop-down box to only display macros from a specific workbook. | ||
The macros that appear in this dialog box will be any that have been recorded as well as any that have been written. | ||
Any macros that have the same name as those in the active workbook are prefixed by the name of the workbook. |
![]() | (Tools > Macro > Macros) dialog box |
You can prevent a macro from appearing in this list by declaring it as "Private" as opposed to Public. Public is the default for all recorded macros. |
|
Step 3 - Assigning to a Shortcut key |
You could run your macro by using a shortcut key. Shortcut keys are case sensitive. | ||
Select (Tools > Macro > Macros) to display the Macro dialog box. | ||
Select the macro that you want to assign a shortcut key to and press the "Options" button. |
![]() | (Tools > Macro > Macros) Options dialog box |
The shortcut key must be a letter. You can either use just the Ctrl key or a combination of both the Ctrl key and the Shift key. | ||
(e.g. Ctrl + " r " or Ctrl + Shift + " R "). | ||
To create a shortcut key that includes the Shift key just press the Shift key while you press the letter. | ||
Any shortcut key that you assign to a macro will take precedence over the built-in shortcut keys, so be careful. | ||
It is possible to assign the same shortcut key to more than one macro in the same workbook using the (Tools > Macro > Macros) dialog box. | ||
You cannot assign the same shortcut key though from the Record Macro dialog box. | ||
If there are any macros that have the same shortcut key assigned, the macro that appears first alphabetically will be run. | ||
If you forget to assign a shortcut key you can always do it at a later date by using the Options button on the (Tools > Macro > Macros) dialog box. |
Step 4 - Assigning to a Graphic or AutoShape |
You could run your macro by using a graphic or AutoShape. | ||
When the AutoShape is clicked (with the left mouse button) the corresponding macro will run. | ||
Add the shape or AutoShape you would like to use to the worksheet. | ||
To insert an AutoShape you have to display the Drawing toolbar. This can be done by selecting (View > Toolbars > Drawing). | ||
Select the graphic or AutoShape with the Right mouse button and select "Assign Macro". |
![]() | Shortcut menu when you right mouse click on a graphic or AutoShape |
This will display the Assign Macro dialog box which looks identical to the Macro dialog box. | ||
Select the macro you want to assign and press OK. |
Step 5 - Assigning to an existing toolbar or drop-down menu |
You could run your macro by using an additional button on either a toolbar or a drop-down menu. | ||
This is slightly more complicated and there are specific pages giving step by step instructions on how to do this following on from this page. | ||
Any macros that are added to existing toolbars and menus will be accessible from any workbook. | ||
These should be stored in your Personal Macro Workbook and not a specific workbook. |
Step 6 - Things to Remember |
Any macros that are available from any additional Excel add-ins are not displayed in the (Tools > Macro > Macros) dialog box. | |||
You can interrupt a running macro by pressing the ESC key. This will display a dialog box allowing you to either Continue, End or Debug your macro. You can also use the key combination (Ctrl + Break) to interrupt a macro. | |||
Macros cannot be undone. This is not technically right and is discussed in the advanced sections. | |||
Selecting "All Open Workbooks" in the Macros in drop-down list will display all macros in any open workbooks including those in the Personal Macro Workbook. | |||
The shortcut key and the description can only be displayed from the Options button on the (Tools > Macro > Macros) dialog box and not from within the Visual Basic Editor. | |||
All shortcut keys are case sensitive. | |||
It is possible to also use worksheet controls to run your macros. For more information on running macros using worksheet controls, please see the Worksheet Controls section. |
| Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved. | < Previous | Top | Next > |