Attach VBA Code to Command Button

Attaching macros to command button in Excel First let’s have a look at the multiple macros from the last video.

  1. Click on Tools in the menu bar of the opened file.
  2. Select Macro and the Visual Basic Editor from the pop-up options
  3. Double-click on module to view the macros firstmacro(), secondmacro() and runmultiplemacros()
  4. Close the VB editor window
  5. Click on view in the menu bar, select Toolbars and Control ToolBox from the pop-up options
  6. From the various icons in the toolbox select the command button
  7. Click, drag and draw on your Excel worksheet a command button of an appropriate size
  8. Right-Click on the button and select ‘properties’
  9. In the properties window rename the caption to Run Multiple Macros
  10. Close the properties window
  11. Right-click the command button again. From the options menu select ‘view code’
  12. Enter the name of the macro that runs multiple macros ‘runmultiplemacros’ between the two already existing lines of code
  13. Close the code window
  14. Click on ‘exit design mode’ icon of the control toolbox
  15. 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

Leave a Reply

Your email address will not be published. Required fields are marked *