title: Deleting a sheet in Excel
body: <p>I tried almost everything that I could find here on StackOverflow but my code keeps throwing the following error:</p>
  
  <blockquote>
    <p>Exception from HRESULT: 0x800A03EC</p>
  </blockquote>
  
  <p>on the line with delete(). I was hoping you people could help me out.</p>
  
  <p>Here's my current code</p>
  
  <pre><code>var xlApp = new Microsoft.Office.Interop.Excel.Application();
  Microsoft.Office.Interop.Excel.Workbook book =
  xlApp.Workbooks.Open(File_name);
  xlApp.DisplayAlerts = false;
  Excel.Worksheet worksheet = (Excel.Worksheet)book.Worksheets[2];
  worksheet.Delete();
  book.Worksheets.Add();
  xlApp.DisplayAlerts = true;
  book.Save();
  book.Close();
  xlApp.Quit();
  Marshal.ReleaseComObject(worksheet);
  Marshal.ReleaseComObject(book);
  Marshal.ReleaseComObject(xlApp);
  </code></pre>
  
  <p>And here's the other code i tried:</p>
  
  <pre><code>oXL.DisplayAlerts = false;
  worksheet = (Excel.Worksheet)theWorkbook.Sheets[i];
  ((Excel.Worksheet)theWorkbook.Sheets[i]).Delete();
  oXL.DisplayAlerts = true;
  oWB.Save();
  oWB.Close(false, missing, missing);
  oSheet = null;
  oWB = null;
  oXL.Quit();
  </code></pre>
  
  <p>And some more variations </p>
  
  <pre><code>Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
  Excel.Workbook oWB;
  Excel.Worksheet oSheet;
  Excel.Workbooks oMWB;
  </code></pre>
  
  <p>and i'm using this reference:</p>
  
  <pre><code>using Excel = Microsoft.Office.Interop.Excel;
  </code></pre>