Be the first user to complete this post

  • 0
Add to List

Assign a Macro to a Button

In Earlier session we saw how to add a button to the top menu of the Excel file (How to Get Access to the ToolBar)

Excel-VBA-MACRO-Assign a Macro to a button — 1
Excel-VBA-MACRO-Assign a Macro to a button — 1

In the Code window we have created two sub routines

Sub Assign_Macro1 ()

....Some Code....

End Sub

Sub Assign_Macro2 ()

....Some Code....

End Sub

Excel-VBA-MACRO -Assign a macro to a button -1
Excel-VBA-MACRO -Assign a macro to a button -2

Now you can assign it to button .

To get the Button on the Excel, Click and Hold the Button icon in the Top menu of the Excel and Then Click + Hold + drag  in Excel Sheet (WorkSheet) to give it proper size.

For the very first time when you create a button another window will prompt automatically to assign Macro to that button

Excel-VBA-MACRO-Assign a Macro to a button— 3
Excel-VBA-MACRO-Assign a Macro to a button— 3

You can click cancel and Assign the Macro later to this Button

you can see that Sheet1.Assign_Macro1 and Sheet1.Assign_Macro2 macro’s are displayed, you can select any of these and click OK. Now when next time when you click the button the select sub routine will be called.

You can change the Assigned Macro or re-size the button or Edit the Text on the button or any other kind of formatting by right click on the button and select the appropriate option from the menu.

Excel-VBA-MACRO-Assign a Macro to a button-4
Excel-VBA-MACRO-Assign a Macro to a button-4



Also Read:

  1. Password Protection to Your Macro Code
  2. Add Tools to Quick Access Tool Bar(Excel Top Bar)
  3. Excel Macro - Visual Basic Editor
  4. How to Enable Macro in Excel
  5. VBA Codes - Record Macro