Attaching macros to command button in Excel First let’s have a look at the multiple macros from the last video.
- Click on Tools in the menu bar of the opened file.
- Select Macro and the Visual Basic Editor from the pop-up options
- Double-click on module to view the macros firstmacro(), secondmacro() and runmultiplemacros()
- Close the VB editor window
- Click on view in the menu bar, select Toolbars and Control ToolBox from the pop-up options
- From the various icons in the toolbox select the command button
- Click, drag and draw on your Excel worksheet a command button of an appropriate size
- Right-Click on the button and select ‘properties’
- In the properties window rename the caption to Run Multiple Macros
- Close the properties window
- Right-click the command button again. From the options menu select ‘view code’
- Enter the name of the macro that runs multiple macros ‘runmultiplemacros’ between the two already existing lines of code
- Close the code window
- Click on ‘exit design mode’ icon of the control toolbox
- Click on the command button to see how both the firstmacro() and the secondmacro() are executed
The Excel training video demonstrates the complete process.
Further reading: Add a button and assign a macro to it in a worksheet