logo
search
VBA & Macro Problems

Fix Excel VBA Code Not Running When a Button Is Clicked

Jason MillerJason Miller Oct 14, 2026 871 views

Question details

The user needs to fix an Excel VBA macro that executes successfully from the Macro dialog but fails to trigger when assigned to a form control or ActiveX button.

Fix Excel VBA Code Not Running When a Button Is Clicked
Product
Microsoft Excel
Device & OS
not provided
Scenario
Triggering an assigned VBA macro using a custom button inside an Excel workbook.
Observed behavior
The macro runs correctly from the dialog box, but clicking the assigned button does nothing or produces an error, possibly due to a recent 32-bit to 64-bit Office upgrade.
Before you start

Ensure that macros are enabled in your Trust Center settings and verify whether your Microsoft Office installation is 32-bit or 64-bit.

Solution 1Recommended

Test the Macro and Button in a New Workbook

Determine if the issue is caused by a corrupted workbook or a malfunctioning form control by isolating the code in a fresh file.

Sometimes, Excel workbooks accumulate corruption over time, causing form controls to disconnect from their assigned macros. Recreating the button and macro in a completely blank workbook helps identify if the issue is file-specific.

1
Create a Blank Workbook

Open Excel and create a completely new, blank workbook.

2
Insert the VBA Code

Press ALT + F11 to open the VBA Editor, click Insert > Module, and paste your existing macro code into the new module.

3
Insert a New Button

Navigate to the Developer tab on the Excel ribbon, click the Insert dropdown, and select the Button (Form Control) icon. Draw the button on your worksheet.

4
Assign and Test

When the Assign Macro dialog appears, select your pasted macro and click OK. Click anywhere on the sheet to deselect the button, then click the button to see if the macro runs.

Test the Macro and Button in a New Workbook
Save as Macro-Enabled: If the macro works perfectly in the new workbook, you can rebuild your file. Remember to save the new workbook as an Excel Macro-Enabled Workbook (.xlsm).
Free Microsoft Office alternative

Try WPS Office for Seamless Macro Compatibility

If Microsoft 365 updates are causing your VBA macros and buttons to break, consider switching to WPS Office. It provides a stable, lightweight environment with excellent support for VBA macros and Excel file formats.

Highly compatible with Microsoft Excel formats (.xlsx, .xlsm).Robust VBA and Macro support to run your existing automated workflows without modification.Lightweight design that installs quickly and consumes fewer system resources.Familiar user interface with no steep learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Excel macro run manually but not from a button?

This typically occurs due to a corrupted form control, strict macro security settings blocking active UI content, or incompatible 32-bit API declarations failing silently when triggered via the interface in a 64-bit Excel environment.

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

Right-click the form control button, select 'Assign Macro' from the context menu, choose the desired macro from the list, and click OK. Ensure the macro is stored in a standard module and is not declared as a 'Private Sub'.

What does the PtrSafe attribute do in VBA?

The PtrSafe attribute tells the VBA compiler that the Declare statement is explicitly safe to run in 64-bit versions of Office. It is absolutely required when calling Windows API functions in 64-bit Excel environments.