Skip to main content

Assigning a Macro to a Button

You can also assign a macro to a button (Form Control). When a macro is assigned to the control, that macro is executed, or played, when the control is clicked.
Take a moment to assign a button for the Helloworld macro you created earlier. Here’s how:

  1. On the Developer tab, click the Insert button in the Controls group.
  2. Select the Button Form Control.
  3. Click the location on the worksheet where you want to place your button.
  4. In the “Assign Macro” dialog box, select the macro you want to assign to the button and then click OK.
  5. You can drag the grab handles to resize the button to your preference.
  6. Right-click the button and click Edit Text, then type a name you like.
  7. Select any other cell to apply the change.
  8. Now, you can run this macro by click the button.

Macros can be assigned to any worksheet object, such as a picture, a text box, a shape, SmartArt graphics, WordArt, or an icon. To assign a macro to any object, right-click the object and select Assign Macro.

Form Controls or ActiveX Controls
Although they look similar, they are very different. Form controls are specifically designed for use with spreadsheets, while ActiveX controls are typically used with Excel user forms. As a general rule, you should always use form controls when working with spreadsheets. Why? Form controls require less overhead, so they perform better, and configuring form controls is much easier than configuring their ActiveX counterparts.

Leave a comment

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

Format your code: <pre><code class="language-vba">place your code here</code></pre>