Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to make a form to manage the formating of the excel by using c# to call macro automatically.
However, when I import the macro to the excel it gets error Exception from HRESULT: 0x800A03EC

I'm using VS 2012 and Excel 2013

C#
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Configuration;
using VBIDE = Microsoft.Vbe.Interop;
using System.Runtime.InteropServices;

private void button1_Click(object sender, EventArgs e)
{
  try
   {
     Microsoft.Office.Interop.Excel.Application m_execl = new Microsoft.Office.Interop.Excel.Application();
       
     Excel._Workbook oWB = (Excel._Workbook)(m_execl.Workbooks.Open(filePath + "myExcel.xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
     m_execl.Visible = true;
                
     Microsoft.Vbe.Interop.VBComponent xlMod;

     xlMod = oWB.VBProject.VBComponents.Import(filePathMarco + "AutoFilter.bas");//<- this get error
      trandRptWeeklyApp.Run("AutoFilter");
      }
      catch (Exception ex)
      {
      }
}
Posted

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