Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While calling macro in excel from c# code , i get this exception System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC

What I have tried:

I use Microsoft.Office.Interop.Excel version 15 and the client machine has Office 2000 and while calling macro , i get the following exception System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC.

This is the code i have trid.

private void RunMacro(Application xlApp, Workbook xlWB, string MacroName, out string status)
       {
           Worksheet xlWS;
           status = string.Empty;
           if (xlApp != null)
           {

               xlWS = (Excel.Worksheet)xlWB.Worksheets.get_Item("Sheet1");// .get_Item(paramsExcelOperatios.WorksheetNo);
               if (MacroName != String.Empty)
               {
                   xlWS.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new Object[] { MacroName });

               }
               else
               {
                   status = "Failure - Macro name should not be empty";
               }

           }
           else
           {
               status = "Failure - Worksheet name is not valid.";
           }
       }
Posted
Updated 27-Mar-19 23:11pm
Comments
lmoelleb 26-Mar-19 4:39am    
Isn't it Office 2013 that is version 15? So your office installation on the machine is 13 years too old for the COM wrapper you use?
CHill60 26-Mar-19 5:06am    
I assume you have tried to run the macro from within Excel?
Member 12766428 26-Mar-19 8:04am    
I used this syntax " xlWS.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new Object[] { MacroName });" to call/execute the macro .
CHill60 26-Mar-19 8:55am    
The reason I asked is because you need to ensure that the macro itself is working in the spreadsheet. This will help determine where the actual problem really is. So the first thing to do is open the Workbook in Excel, go to the "Macros" menu, "View Macros", locate the macro you are having problems with and click "Run".

You might want to advise your "client" that Office 2000 is riddled with security holes and is not compatible with Windows 10 - it should really be updated
Dave Kreskowiak 26-Mar-19 8:21am    
Your code is written against a COM wrapper for a newer version of Office. That wrapper won't work properly against an older version of Office.

The real question is why on earth would you want to support such an old version of Office?

1 solution

This is bad idea, bad approach!

Anything VBA code can do with Excel objects, C# is able to do the same. Note, taht C# offers much more than VBA, for example: Linq.
 
Share this answer
 
Comments
lmoelleb 28-Mar-19 6:01am    
Hard to say without the use case known. Are users of Excel also executing the macro? Are macros meant to be written by people who know Excel, but do not have the knowledge to program C# - or even access a development system. If they use Office 2000, it is probably not the most progressive environment this is needed in. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900