Excel Macro Button: How to Add, Assign, and Run Macros

VBA & macros · Updated November 11, 2026

An Excel macro button is a clickable control that runs a VBA macro in a workbook. In Excel for Microsoft 365 on Windows, select Developer > Insert > Button under Form Controls, draw the button on the sheet, choose a macro in the Assign Macro dialog, and select OK.

What an Excel macro button does

A macro button gives someone a visible way to start a task without opening the Visual Basic Editor or remembering a keyboard shortcut. The task might format a report, clear an input area, refresh a process, or show a message. The button itself does not contain the automation: it points to a macro, which is a VBA procedure stored in the workbook or another available macro location.

This distinction matters when you copy or share a worksheet. A button can still be visible even if its assigned macro has been removed, renamed, or is unavailable to the recipient. Conversely, a macro can exist in the workbook without any button attached to it. A working setup needs both the control and an accessible macro with a compatible procedure name.

Add a Form Control button in Excel for Windows

For a straightforward worksheet button, use a Form Control rather than an ActiveX control. Form Control buttons are designed for common tasks such as running a macro and are generally simpler to distribute. Follow these steps in the desktop version of Excel for Microsoft 365 on Windows:

  1. If the Developer tab is not visible, select File > Options > Customize Ribbon. In the list of main tabs, check Developer and select OK.
  2. Open the worksheet where the button should appear. Select Developer > Insert. In the Form Controls section, select Button.
  3. Click and drag on the worksheet to set the button’s size. When you release the mouse, Excel opens the Assign Macro dialog.
  4. Select an existing macro and choose OK. To create the macro first, cancel the dialog, add the procedure in a standard VBA module, then return to assign it.
  5. Click the button to run the assigned macro. To change its label, right-click the button, choose Edit Text, and type a concise instruction such as Run Report.

Position the button near the cells or instructions it relates to, but leave enough room to select nearby cells. A Form Control can be moved or resized by selecting it; right-clicking opens its context menu. When the control is selected, dragging its border moves it, while the handles change its size.

Create a simple macro to assign

A macro assigned to a Form Control button should normally be a public procedure with no required arguments, placed in a standard module. In the Visual Basic Editor, choose Insert > Module, then add a procedure like this. It displays a confirmation message rather than changing worksheet data:

Sub ShowButtonMessage()
    ' Confirms that the assigned macro ran.
    Dim message As String
    message = "The macro button works."
    MsgBox message, vbInformation, "Excel macro"
End Sub

To open the editor on Windows, select Developer > Visual Basic. After adding the procedure, return to Excel, insert a button, and select ShowButtonMessage in the Assign Macro dialog. Save the file as an Excel Macro-Enabled Workbook (*.xlsm); an ordinary .xlsx file does not retain VBA code when saved. Keep a separate copy before running any macro that changes data, because macro actions cannot be undone with Ctrl+Z.

The example is intentionally harmless. A real procedure could update cells or format a report, but it should be scoped carefully. For instance, a macro that clears a range should identify the exact worksheet and range it is meant to change rather than relying on whichever sheet happens to be active.

Choose between a Form Control, a shape, and ActiveX

There are several ways to make a worksheet object run a macro, but they are not interchangeable in every situation:

  • Form Control button: The usual choice for a simple, labeled control. Insert it from Developer > Insert > Form Controls, then assign a macro. It is relatively easy to use and does not require ActiveX.
  • Shape: A shape can be styled more freely. Select Insert > Shapes, draw a shape, then right-click it and choose Assign Macro. Shapes can be useful when a more designed appearance matters, though they are not presented as a dedicated button control.
  • ActiveX control: ActiveX offers additional control behavior in some Windows desktop workflows, but it involves design mode and event code, and it is not supported in Excel for Mac. It is usually unnecessary for a basic “click to run a macro” task.

For a shared workbook intended to work across Windows and Mac desktop Excel, a Form Control or assigned shape is generally a more practical starting point than ActiveX. Whichever object you choose, test the workbook in the Excel versions and environments your recipients will actually use.

Assign, change, or remove the button’s macro

A button can be connected to a different macro later. Right-click the Form Control and select Assign Macro, choose the intended procedure, and confirm. The same dialog is useful for checking which macro is currently connected. If a macro has been renamed or deleted, assign a replacement that exists and is available in the workbook.

To remove the control without deleting worksheet data, right-click its edge and delete the object. On some sheets, right-clicking directly on the button may first put the text into editing mode; click outside, then right-click the border to access the object menu. If the sheet is protected, you may need to unprotect it or adjust protection settings before changing controls. Protecting a sheet can also affect whether users can select or interact with objects, depending on the protection options.

For a shape, right-click the shape and select Assign Macro to change its action. If you only want to change what the shape says, select its text rather than changing the macro assignment. Keeping labels action-oriented—such as “Create Summary” rather than “Click Here”—helps users understand what will happen.

Excel for Mac and Excel for the web

Excel for Mac supports VBA macros, but the ribbon layout and some control capabilities differ from Windows. In many Microsoft 365 for Mac releases, you can show the Developer tab through Excel > Preferences > Ribbon & Toolbar, then use the Developer ribbon to work with macros and controls. Exact labels and available controls can vary by release. ActiveX controls are not supported on Mac, so avoid them when Mac users need to use the workbook.

Excel for the web does not run, create, or edit VBA macros. A workbook containing VBA can be stored and opened in the web app, but the macro button will not execute its VBA procedure there. Users who need to run it should open the file in the desktop Excel app, with macros permitted by their organization’s security settings. If browser access is essential, consider whether the task can be redesigned using supported web features or an approved automation option rather than a VBA button.

Security, saving, and sharing

Macros can make changes to files and data, so Excel applies security controls. A recipient may see a security warning or find that macros are disabled, particularly when a workbook came from the internet or another untrusted location. A button cannot bypass that policy. Only enable macros in a workbook when you trust its source and understand what its code is intended to do; do not advise users to enable all macros globally just to make one button work.

Before sharing, check the following practical details:

  • Save a macro-containing workbook as .xlsm, not .xlsx, and make a backup before running code that changes content.
  • Confirm the macro is present, the button is assigned to the right procedure, and the procedure can run without relying on another person’s local files or settings.
  • Test a copy of the workbook with the same desktop platform and security restrictions the recipient is likely to have.
  • Explain what the button does and whether it changes or clears information. Give users a way to recover, such as keeping the original data or a separate backup.

Macros are not undone by Excel’s normal Undo command. This is why a “clear,” “replace,” or “update” button deserves particular care: it may make changes that are difficult to reverse, even when the button is only one click.

Common problems and how to diagnose them

If clicking the button appears to do nothing, first check whether the workbook is open in Excel for the web or whether macros are disabled. Then right-click the control, choose Assign Macro, and verify that a procedure is selected. If the assigned procedure is missing, use the Visual Basic Editor to confirm the macro still exists in a standard module and has not been renamed.

If Excel reports that it cannot run the macro, check that the workbook was saved as .xlsm and that the procedure name and workbook reference are valid. A macro stored in a different workbook may not be available when that workbook is closed. Also check whether the sheet is protected or the button is being edited rather than clicked. A Form Control is activated by a normal click when it is not selected for editing.

If the button has disappeared, it may have been deleted, moved off the visible area, or hidden behind another object. Use the Selection Pane, available from Home > Find & Select > Selection Pane, to inspect worksheet objects. If the button runs the wrong task, reassign it rather than assuming the text label determines its action: the displayed words and the assigned macro are separate settings.

Frequently Asked Questions

Can I add a macro button without writing VBA?
You can add the button without writing code if the workbook already contains a suitable macro. The button still needs a macro to run; Excel does not create the automation just because you insert a control.

Why is the Developer tab missing?
On Windows, select File > Options > Customize Ribbon and check Developer. On Mac, use Excel > Preferences > Ribbon & Toolbar in releases that provide that path, then enable Developer.

Will an Excel macro button work in a browser?
No. Excel for the web does not execute VBA macros, so a button assigned to a VBA procedure will not run there. Open the macro-enabled workbook in desktop Excel to use the VBA button.

Can a shape run a macro instead of a button?
Yes. Insert a shape, right-click it, and select Assign Macro. This is useful when you want more control over the object’s appearance than a standard Form Control provides.

Can I undo a macro after clicking its button?
Usually not with Ctrl+Z. VBA actions generally clear Excel’s normal undo history, so save a separate copy before running macros that alter or delete data.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.