Assign a macro to a button
You can use a button (a form control) to run a macro that performs an action when a user clicks it. For example, you might use a button to automate the printing of a worksheet, the filtering of data, or the calculation of numbers.
After you create a macro , you can assign it to a button you click to run the macro . You can assign a macro to a button on the Quick Access Toolbar or to a button in your own personal group on the ribbon.
If you want a macro button to be available in other workbooks, assign it to a macro that was created in a personal workbook .
Add a macro button to the Quick Access Toolbar
Click File > Options > Quick Access Toolbar .
In the Choose commands from list, click Macros .
Select the macro you want to assign a button to.
Click Add to move the macro to the list of buttons on the Quick Access Toolbar.
To replace the default macro icon with a different button for your macro, click Modify .
Under Symbol , select a button icon for your macro.
To use a friendlier name for the button, in the Display name box, enter the name you want.
You can enter a space in the button name.
Click OK twice.
The new button appears on the Quick Access Toolbar, where you can click it to run the macro.
Tip: When you save the workbook , buttons you assign to macros in the personal workbook will be available in every workbook you open.
Add a macro button to your own group on the ribbon
Click File > Options > Customize Ribbon .
Under Customize the Ribbon , in the Main Tabs list , check the Developer box if it is not already checked.
Pick the tab where you want to add your own group.
For example, pick Home , to add your group to the Home tab.
Select New Group .
That adds New Group (Custom) to the tab you picked.
To use a better name for your new group, click Rename , type the name you want in the Display name box, and then click OK .
You can enter a space in the name. For example, type My Macros .
To add a macro to the group, in the Choose commands from list, click Macros .
Select the macro you want to add to your new group, and then click Add . The macro is added to the My Macros group.
To use a friendlier name, click Rename , and then type the name you want in the Display name box.
You can enter a space in the name.
Your new group appears on the tab you picked, where you can click the button to run the macro.
On the Developer tab, in the Controls group, click Button .
If the Developer tab is not available
Go to Excel > Preferences... > Ribbon & Toolbar .
In the Customize the Ribbon section, under Main Tabs , check the Developer check box, and press OK.
Click the worksheet location where you want the upper-left corner of the button to appear.
In the Assign Macro dialog box, click the name of the macro that you want to assign to the button, and then click OK .
To resize the button, drag the sizing handles.
To specify the control properties of the button, Control+Click or right-click the button, and then click Format Control .
Excel 2011 for Mac
On the Developer tab, in the Forms Control group, click Button .
Under Customize , select the Developer check box.
Need more help?
Expand your skills.
EXPLORE TRAINING >
Get new features first
JOIN MICROSOFT 365 INSIDERS >
Was this information helpful?
Thank you for your feedback.
- Microsoft Office
How to Add Macros and Buttons to Outlook
- Facebook Opens a new window
- Twitter Opens a new window
- Reddit Opens a new window
- LinkedIn Opens a new window
- Windows Server |
- Spiceworks General Support |
- Active Directory & GPO |
- Microsoft Office |
- General Software
1. Open Outlook and press Alt+F11 (This will open the VBA window)
2. Expand Project1 (VbaProject.OTM), expand Microsoft Outlook Objects, highlight and right click ThisOutlookSession, select insert and then Module (do this as many times as you need to pending on number of buttons you want to add will end up with Module1, Module2, etc)
3. Double click Module1, this will open the VbaProject.OTM - Module1 window and add the desired code, then save
a. Go to the Outlook Window, select File, Options, custom ribbon b. Select and expand Home (Mail) from the right hand column and then click New Group at the bottom (This will add a new group, you can rename it by clicking Rename) c. Hit the dropdown box from the left hand column under Choose commands from: and select macros. This will add the macro you just created (it will be named project1.xxxxx by default, the xxxxx will be whatever the function of the macro is) Select from the left hand column and click Add>>, rename it to whatever you would like the button to read, then OK and OK to add it to your newly created group. This should also make it appear on your Home tab.
4. Enable Macros to whatever level you feel comfortable with, close and reopen outlook
5. Test macro
6. If you need to add more scripts for additional buttons just open the VBA Window (Alt+F11) and repeat steps 3 and A-C (Of course be sure to select a different module, additional ones will be named Project1.Module2.xxx and so on)
1 Steps total
Step 1: additional resources.
I also have some helpful links that I would be willing to share. Let me know if you need any further help and I would be happy to share them
This was the first time I have ever used VBA, macros, or buttons. I am sure there is an better way of doing this so, if you know of one please let me know.
Otherwise I hope this saves somebody some hours because it took me a while to figure this out.
Thank you SO much for this. This is the only place that spelled out how to add multiple macros correctly - the key is the DOUBLE-CLICK on each module (Step 3).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Writing an Outlook Macro
- 2 minutes to read
- 5 contributors
A macro is any public subroutine in a code module. A function or a private subroutine cannot be a macro, and a macro cannot be located in a class or form module.
To create a new macro
In Outlook, on the Developer tab of the Microsoft Office Fluent ribbon, click Visual Basic .
In the Project window, double-click the module you want to contain the macro.
On the Insert menu, click Procedure .
In the Name box, type a name for the macro. The name cannot contain spaces.
Click OK . The template for the macro subroutine appears in the code module window.
Type the code you want to run in the body of the subroutine.
For more information about using the Visual Basic Editor, see the Visual Basic Editor Help. Once you've created a macro, you can create a menu item or toolbar button that will run the macro when you click it.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Press the File button next to the Home tab and choose Options. Select the section: Quick Access Toolbar In the drop down list “Choose commands from” select: Macros. The list below will now show you all your macros. Select the macro that you wish to create a button for and press the Add >> button.
On the Developer tab, in the Code group, click Macros. In the Macro dialog box, under Macro name, select the macro that you want, and then click Run. Here are details about the other options in this dialog box. Macro name Specifies the name of the macro or add-on to step into, edit, create, delete, or run. Macro list Lists all macros available.
4. Enable Macros to whatever level you feel comfortable with, close and reopen outlook. 5. Test macro. 6. If you need to add more scripts for additional buttons just open the VBA Window (Alt+F11) and repeat steps 3 and A-C (Of course be sure to select a different module, additional ones will be named Project1.Module2.xxx and so on)
In Outlook, on the Developer tab of the Microsoft Office Fluent ribbon, click Visual Basic. In the Project window, double-click the module you want to contain the macro. On the Insert menu, click Procedure. In the Name box, type a name for the macro. The name cannot contain spaces. Click OK.