How do I assign a macro to a button in Excel VBA?

In this article, we shall learn how to assign a Macro to a button in Excel. Lets start.This article is part of my series: Excel VBA & Macros A Step by Step Complete Guide.Tabl

How do I assign a macro to a button in Excel VBA?

In this article, we shall learn how to assign a Macro to a button in Excel. Lets start.

This article is part of my series: Excel VBA & Macros  A Step by Step Complete Guide.Table of Contents hide(Step by Step) How to Assign a Macro to a Button in ExcelClick the button and the Macro will be activatedDownload Working FileFurther Readings

(Step by Step) How to Assign a Macro to a Button in Excel

After you have recorded and tested a macro, you may want to assign your macro to a button placed in a worksheet. You can follow these steps to do so:

  1. If your macro is a general-purpose macro and you plan to use it in more than one workbook, make sure that this macro is stored in your Personal Macro Workbook.
  2. Choose Developer  Controls  Insert, and then click the icon identified as Button (Form Control). To find out the form control button, move your mouse pointer over the icons, and you will see a ToolTip that will describe the control. See the following figure.
how to assign a macro to a button in Excel

Form Control Button.

  1. Now select the worksheet and drag in the worksheet to draw the button. Whenever you release the mouse button, the Assign Macro dialog box will appear.
  2. Select the macro from the list.
  3. Click OK to close the Assign Macro dialog box.
Assigning a macro to a button

Assign Macro dialog box.

  1. A button will appear on the worksheet. You can change the text that is displayed on the button to make it descriptive. To do so, right-click the button, choose Edit Text from the shortcut menu, and make your changes.
Assigning a macro to a button

Click this button to activate the TimeStamp macro.

Click the button and the Macro will be activated

After performing these steps, select any cell in the worksheet and click the button to execute the assigned macro in it.

Download Working File

Time-Stamp.xlsm

Happy Excelling


Further Readings

  • About Macro Security in Excel
  • How to Edit Macros in Excel (2 Methods)
  • A Macro example created using VBA
  • VBA Macro to Delete Row if Cell Contains Value in Excel (2 Methods)

Video liên quan