title: Excel Exception from HRESULT: 0x800A03EC
body: <p>I am trying to update a program that does work for office 2010 but gives an error for 2013.</p>
  
  <p>The code I am running is this:</p>
  
  <pre><code>private static bool writeToExcel(DataTable dT)
  {
      // Create a new Excel document
      Console.Write("Opening Excel...");
      Excel.Application objExcel = new Excel.Application();
      objExcel.Visible = false;
      Excel.Workbooks objBooks = objExcel.Workbooks;
      Excel.Workbook objBook = objBooks.Add();
      Excel.Worksheet objSheet = (Excel.Worksheet)objExcel.Worksheets["Sheet1"]; objSheet.Name = "Data";
      Excel.Worksheet newWorksheet;
      newWorksheet = (Excel.Worksheet)objExcel.Worksheets.Add();
      Excel.Worksheet objSheet2 = (Excel.Worksheet)objExcel.Worksheets["Sheet2"]; objSheet2.Name = "Data2";
      Excel.Range objRange;
  
      objSheet2.Cells[2, 1] = "###";
      objSheet2.Cells[3, 1] = "@@@";
      objSheet2.Cells[4, 1] = "$$$";
  
      objSheet2.Cells[1, 2] = "%%%";
      objSheet2.Cells[2, 2] = %%%Count;
      objSheet2.Cells[3, 2] = %%%RespCount;
      objSheet2.Cells[4, 2] = Math.Round(%%%RespCount / %%%Count, 1);
  
      objSheet2.Cells[1, 3] = "^^^";
      objSheet2.Cells[2, 3] = ^^^Count;
      objSheet2.Cells[3, 3] = ^^^RespCount;
      objSheet2.Cells[4, 3] = Math.Round(^^^Count / ^^^RespCount, 1);
  
      objSheet2.Cells[1, 5] = "&amp;&amp;&amp;";
      objSheet2.Cells[2, 5] = &amp;&amp;&amp;;
      objSheet2.Cells[3, 5] = &amp;&amp;&amp;Resp;
      objSheet2.Cells[4, 5] = Math.Round(&amp;&amp;&amp; / &amp;&amp;&amp;Resp, 1);
  
      objSheet2.Cells[1, 6] = "***";
      objSheet2.Cells[2, 6] = ***;
      objSheet2.Cells[3, 6] = ***Resp;
      objSheet2.Cells[4, 6] = Math.Round(*** / ***Resp, 1);
  
  
      // Add the column headers
      int colCount = 1;
      int rowCount = 1;
      foreach (DataColumn column in dT.Columns)
      {
          Console.Write(".");
          objSheet.Cells[rowCount, colCount] = DB.GetColumnName(column.ColumnName);
          if (column.DataType == System.Type.GetType("System.String"))
          {
              objRange = objExcel.Range[objExcel.Cells[2, colCount], objExcel.Cells[dT.Rows.Count + 1, colCount]];
              objRange.NumberFormat = "@";
          }
          if (column.DataType == System.Type.GetType("System.DateTime"))
          {
              objRange = objExcel.Range[objExcel.Cells[2, colCount], objExcel.Cells[dT.Rows.Count + 1, colCount]];
              objRange.NumberFormat = "m/d/yy h:mm AM/PM";
          }
          colCount++;
      }
  
      // Format the column headers
      Console.WriteLine();
      Console.Write("Adding columns...");
  
      try
      {
          objSheet.Range[objExcel.Cells[rowCount + 1, 1], objExcel.Cells[rowCount + 1, dT.Columns.Count]].Select();
      }
      catch (Exception e)
      {
          Console.WriteLine(e);
      }
  }
  </code></pre>
  
  <p>The Error I get when I try it on a Win 7 PC running Office 2013 is this.</p>
  
  <pre><code>System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC 
  at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, 
     ExcepInfo&amp; excepInfo, UInt32 argErr, String message)
  at CallSite.Target(Closure , CallSite , Object , Object , Object )   
  at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
  at CscSurveyReporter.Program.writeToExcel(DataTable dT) in c:\tfs_csc\csc\CscSurveyReporter\CscSurveyReporter\Program.cs:line 236
  </code></pre>
  
  <p>The line I am having the exception on is:</p>
  
  <pre><code>objSheet.Range[objExcel.Cells[rowCount + 1, 1], objExcel.Cells[rowCount + 1, dT.Columns.Count]].Select();
  </code></pre>
  
  <p>I have looked online for a solution and I have tried to update the Microsoft.Office.Interop.Excel and I have also tried to remove a registry folder but nothing I have found and tried has worked. </p>