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.
5) Using a MacroButton placed within the document.

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.

microsoft excel docs

The default is to display all the macros that are currently available from "All active templates and documents" (including and any other global templates).
It is possible to change the "Macros in" drop-down box to only display macros from a specific document.
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 do not have unique names are prefixed by the name of the module
If two macros have the same name and appear in modules with the same name then they are prefixed by the project name.

microsoft excel docs

You can prevent a macro from appearing in this list by declaring as "Private" as opposed to Public. Public is the default for all recorded macros.

Private Sub Macro1() 
' Macro recorded #date# by Russell Proctor
End Sub

Assigning to a Shortcut key

You could run your macro by using a shortcut key. Shortcut keys are case sensitive.
Select (Tools > Customize) to display the Customize dialog box.
At the bottom of the dialog box press the Keyboard button to display the "Customize Keyboard" dialog box.
In the Categories listbox scroll down and select "Macros".
Select the macro that you want to assign a shortcut key to in the right hand listbox.

microsoft excel docs

The shortcut key can be any character including letters and numbers and you must also use the Ctrl key.
(e.g. Ctrl + Shift + "A").
To create the shortcut key just press down the Ctrl key while you press the other keys.
Any shortcut key that you assign to a macro will take precedence over the built-in shortcut keys so be careful.
You can reassign a shortcut key which is already being used but be aware that you will not be able to use this key combination unless you reset all your keyboard shortcut keys.
Word at least tells you which shortcut keys are already being used which is more than Excel does.
There is currently no way of resetting a single key assignment. Your only option is to reset all the keyboard assignments.

Assigning to a Graphic or AutoShape

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 document.
These should be stored in an add-in and not a specific document or template.

Assigning to the MacroButton Field

Press (Ctrl + F9) to insert a set of Field code brackets
{ MACROBUTTON Macroname Press this to run macro }
Right click the area arnd toggle field code.
If you want the field to resemble a button you can use the (Format > Font | Paragraph | Borders and Shading) dialog boxes.

Changing the ToolTip Text

If your macro name has capital letters separating the different words such as BoldText, then the tooltip text for that macro will automatically be "Bold Text".
You can easily change the tooltip text by running the following line of code in the Immediate window

Commandbars("MyToolBar").Controls("MyButton").ToolTipText = "my tooltip text" 

This line of code only needs to be run once


Any macros that are available from any additional Word add-ins are not displayed in the (Tools > Macro > Macros) dialog box.
If you do not want to reassign any of the built-in keyboard shortcuts then you can use the Ctrl key combined with a number from the number keypad.
You can quickly print a list of all the shortcut keys that have been assigned from the (File > Print) dialog box. In the Print What list, select "Key assignments".

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext