Fix an Excel Macro That Fails from a Form Control Button
Question details
The user needs an Excel macro to run correctly when launched from a Form Control button.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A macro runs from the Developer tab but is also assigned to a Form Control button on a worksheet.
- Observed behavior
- The macro fails when the button is clicked, even though it runs from the Developer tab. Recreating the button has not resolved the issue.
Confirm that the worksheet button is a Form Control, not an ActiveX control. Open the workbook containing the macro and note any error message displayed when you click the button.
Verify the Form Control button's macro assignment
Use this check to make sure the button calls the intended macro in the intended workbook.
Right-click the Form Control button and select Assign Macro.
In the Assign Macro dialog, select the intended macro and check the workbook name if one is shown. Click OK to confirm the assignment.
On the Developer tab, select Visual Basic. In the Project pane, confirm that the assigned procedure is a public Sub with no required arguments in a standard module under Modules.
Return to the worksheet and click the button. If it still fails, note the error and inspect the macro's workbook and worksheet references.

Make workbook references explicit and debug the macro
Use this approach when the assignment is correct but the macro depends on the active sheet, selection, or caller.
Recreate the Form Control button and reassign the macro
Try a new button if the existing control or its assignment may be damaged.
Work with Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with spreadsheets. Its support for common Microsoft Office formats helps you move everyday files between applications; test macro-dependent workbooks separately because VBA and Form Control behavior can differ.

Frequently Asked Questions
Why does my macro work from the Developer tab but not from the button?
The button may be assigned to a different macro or workbook, or the code may depend on the active sheet, selection, or caller. Right-click the button, select Assign Macro, and then inspect those references in Developer > Visual Basic.
Where should a macro assigned to a Form Control button be stored?
Place the assigned public Sub, with no required arguments, in a standard VBA module. Open Developer > Visual Basic and check the Modules folder in the Project pane.
How can I find the line that fails when I click the button?
In the VBA editor, set a breakpoint near the beginning of the assigned procedure with F9. Click the worksheet button, then use F8 to step through the code when execution pauses.
Will deleting and recreating the button fix the macro?
It can fix a problem with the control or its assignment, but it will not correct faulty VBA or workbook references. If the new button fails too, inspect and debug the macro.
What does ThisWorkbook refer to in VBA?
ThisWorkbook refers to the workbook containing the VBA code. Use it with an explicit worksheet and range, such as ThisWorkbook.Worksheets("Sheet1").Range("A1"), when that is the workbook you intend to access.




