Fix Optional Arguments in C# COM Add-ins for Excel and VBA
Question details
The user needs C# COM add-in methods to handle omitted optional arguments consistently in Excel and VBA.

- Product
- Microsoft Excel and C# COM add-ins
- Device & OS
- not provided
- Scenario
- An Excel or VBA caller invokes a COM-exposed C# method with one or more optional arguments omitted.
- Observed behavior
- Omitting arguments can produce an Excel #VALUE! error or a VBA type mismatch, even when calls supplying all arguments work.
Locate the C# interface and method signature, the registered COM type library, and example calls from both Excel and VBA. Record which arguments are omitted and whether the failure changes after restarting Excel.
Inspect and correct the COM parameter definitions
Use this approach to investigate whether the exposed type library matches the optional parameters expected by Excel and VBA.
Open the COM-visible interface in your C# project and check each parameter's type, default value, and whether it is passed by value or by reference. For example, a method may declare int Test(int a = 1, int b = 1).
Open the registered type library in a COM type library viewer, or open the VBA editor and press F2 to inspect the library in Object Browser. Check that the exposed method shows the expected parameter types and optional defaults.
If the exposed definitions are incorrect, update the COM-visible interface, rebuild the add-in, and register the updated assembly and type library using your add-in's deployment procedure.
Close Excel and start a fresh session to test the Excel call. Close and restart Excel again, then test the VBA call from the Visual Basic editor, comparing calls with all arguments supplied and with arguments omitted.
Pass default values explicitly as a workaround
Use explicit values when omitted arguments remain unreliable or while you investigate the COM interface.
Work with Excel files in WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Office files. It can help with everyday spreadsheet work and migration, but it does not fix Microsoft Excel COM add-in errors.

Frequently Asked Questions
Why does an omitted argument cause a type mismatch in VBA?
The COM-exposed parameter type, optional flag, or default may not match what the VBA caller expects. Press F2 in the VBA editor to inspect the method in Object Browser, then compare it with the C# interface and type library.
How can I work around an optional argument that fails when omitted?
Pass the intended default explicitly in the Excel formula or VBA procedure. For a method with defaults of 1 for both parameters, supply both values, such as Test(1, 1), using the caller's required syntax.
Why should I test Excel and VBA in separate sessions?
Fresh sessions help you compare behavior without relying on the state of an earlier test. Close and restart Excel before testing each caller, and confirm that the intended add-in and type library are registered.
Can WPS Office repair an Excel COM add-in?
No. WPS Office is an alternative for opening and editing spreadsheet files; it does not repair Microsoft Excel's COM registration or add-in parameter definitions.




