Fix XLAM Ribbon Error: Wrong Number of Arguments in Excel VBA
Question details
The user needs to resolve an Excel error stating 'Wrong number of arguments or invalid property assignment' when launching a macro from a custom XLAM Ribbon button.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Running a macro via a custom Ribbon button in an XLAM add-in.
- Observed behavior
- Excel throws a 'Wrong number of arguments or invalid property assignment' error because the macro does not accept the Ribbon control argument passed by the custom button click.
Before editing your VBA code, ensure you have enabled the Developer tab in your Excel ribbon and have access to the Visual Basic for Applications (VBA) editor.
Update the VBA Procedure to Accept the IRibbonControl Parameter
Modify your macro's signature so it properly receives the control argument sent by the custom Ribbon button.
When a macro is triggered from a custom Ribbon button, Excel automatically passes an IRibbonControl object to the procedure. If your macro is defined without parameters, Excel cannot pass this argument, resulting in the 'Wrong number of arguments' error.
Press Alt + F11 in Excel to open the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, find the module containing the macro linked to your custom Ribbon button and double-click it.
Change the first line of your macro from 'Sub yourMacroName()' to 'Sub yourMacroName(control As IRibbonControl)'.
Save your VBA project, close the editor, and reload the XLAM add-in in Excel to apply the changes before testing the button again.

Looking for a Seamless Excel Alternative? Try WPS Office
If you frequently encounter complex VBA errors or Ribbon add-in issues in Microsoft Office, consider switching to WPS Office. It provides a highly compatible spreadsheet environment with familiar interfaces, allowing you to seamlessly migrate your daily tasks.
- 1. Download WPS Office: Visit the official WPS website and download the free WPS Office suite for your operating system.
- 2. Install and Launch: Run the downloaded installer and follow the on-screen instructions. Once installed, open WPS Spreadsheet.
- 3. Open Your Spreadsheets: Open your existing Excel workbooks directly in WPS Office to continue working seamlessly with full format compatibility.

Frequently Asked Questions
Why does my macro work from the Developer tab but not from a custom Ribbon button?
When you run a macro directly from the Developer tab, no arguments are passed to it. However, when triggered via a custom Ribbon button, Excel automatically passes an IRibbonControl object. If your macro isn't designed to accept this argument, it triggers a 'wrong number of arguments' error.
What is an IRibbonControl parameter?
The IRibbonControl parameter is an object passed by Excel's Ribbon UI to a callback procedure (your macro). It contains information about the specific Ribbon control (such as its ID) that triggered the action.
How do I check my custom Ribbon XML callback signature?
You can inspect your XLAM add-in's Ribbon XML using a Custom UI Editor tool. Look for the 'onAction' attribute of your button; the value assigned to it must exactly match the name of the macro you defined in your VBA module.




