OzGrid

Assign Macros in Excel

< Back to Search results

 Category: [Excel]  Demo Available 

Assign Macros in Excel

 

Assign Macros in Excel/Assigning Excel Macros to Objects

ASSIGNING MACROS TO A SHORTCUT KEY, OBJECT, COMMAND BUTTON OR A TOOLBAR

Once you have recorded your excel macro, there are a number of ways that you can run it. To go via the Macro dialog box in the menu system go to Tools>Macro>Macros (Alt+F8), click on the name of the macro you wish to run and select Run. There are also a number of much quicker alternatives:

ASSIGNING A MACRO TO AN OBJECT

To assign a macro to an object, select an object from the drawing toolbar, then right click and go to Assign Macro, select the macro you wish to assign, then click OK. (You can double click as well)

ASSIGN A MACRO TO A SHORT-CUT KEY

Assigning a macro to a shortcut key can be done at the first stage of recording a macro, when your Record Macro dialog first pops up to ask you to give it a name. The second step asks for a Shortcut key. Note that if you select a shortcut that is already in use (such as Ctrl C for Copy), the original command will be overridden and replaced with your macro.

If you have already created your macro and wish to then go back and assign it to a shortcut key, go to Tools>Macro>Macros (Alt+F8), then select the Options button and enter in the shortcut key you would like to use.

ASSIGNING A MACRO TO A BUTTON FROM THE FORMS TOOLBAR

You can easily assign a macro to a button from the Forms Toolbar. To do this, go to View>Toolbars>Forms to show your Forms Toolbar, then select the Button icon and draw a button on your worksheet. Immediately when you let go of your button, the Assign Macro dialog will pop up. Select the macro you wish to assign, then click OK. Note that if you select the border of the button, then right click, extra options, such as the ability to name your button, and again the option to Assign a Macro to the button if you have not already done so.

ASSIGNING A MACRO TO A COMMAND BUTTON FROM THE CONTROL TOOLBOX

You can also assign a macro to a Command Button from the Control Toolbox, giving you much greater flexibility than using a button from the Forms Toolbar. This is because the Control Toolbox uses ActiveX controls. Go here to read the difference between ActiveX controls and other controls. To do this, go to View>Toolbars>Control Toolbox to show the Control Toolbox Toolbar, then select the Command Button icon and draw a button on your worksheet. Note than when you do this the button becomes an embedded Object of the Worksheet Object, giving you greater flexibility and access to many visual properties of the button, by right clicking on the Command Button and choosing Properties. To assign a macro, double click on the button and type in the words: Run "name_of_your_macro_here" make sure thename of your macro is in inverted commas.

ASSIGNING A MACRO TO A TOOLBAR

The final way you can run a macro is to assign it to a toolbar. To do this, go to View>Toolbars>Customize and select the Commands tab. Scroll through the Categories list until you get to the Macros option and select it. in the right pane, select Custom Button (smiley face) and drag to the desired location your toolbar. Click the Modify Selection button and you will see the Assign Macro option at the bottom of the list. Click on it and the Assign Macro dialog will pop up. Select the macro you wish to assign and click OK. There are many other options here such as giving a Name to your button, or changing the image. We want click Close when you have made any other changes.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

Advanced Excel Dynamic Named Ranges
Excel Advanced Filter
Excel: Alternate Row Colors/Color Banding

 

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)