title: .NET Excel Interop Worksheet.Copy failing after 255 sheets
body: <p>Got a question that I've found only rarely asked, and seen no good responses for.</p>
  
  <p>Very simple piece of code, in VB.NET:</p>
  
  <pre><code>Imports System.Data
  </code></pre>
  
  <p><code>Imports System.IO</code></p>
  
  <p><code>Imports System.Runtime.InteropServices</code></p>
  
  <pre><code>Dim anExcelApplicationClass As Microsoft.Office.Interop.Excel.Application
  
      anExcelApplicationClass = New Microsoft.Office.Interop.Excel.Application
      anExcelApplicationClass.Visible = False
      anExcelApplicationClass.UserControl = False
      anExcelApplicationClass.DisplayAlerts = False
      anExcelApplicationClass.ScreenUpdating = False
  
      Dim devWorkbooks As Workbooks
      Dim devWorkbook As Workbook
      Dim masterTempWorksheet As Worksheet
      Dim tempWorksheet As Worksheet
  
      devWorkbooks = anExcelApplicationClass.Workbooks
      devWorkbook = devWorkbooks.Open(DevFilePath, 0, False, 5, "", "", False, XlPlatform.xlWindows, "", True, False, 0, True, False, False)
  
      Dim tempCounter As Integer = 0
      While tempCounter &lt; 500
          tempCounter = tempCounter + 1
          masterTempWorksheet.Copy(Type.Missing, masterTempWorksheet)
          tempWorksheet = CType(devWorkbook.Sheets(3), Worksheet)
          tempWorksheet.Name = tempCounter.ToString()
      End While
  </code></pre>
  
  <p>For me, after 255 iterations, the code fails with a rather useless error of "Exception de HRESULT : 0x800A03EC".</p>
  
  <p>From research, I've seen some people saying this is the limit of the number of worksheets, but I've seen others suggesting that there is no real limit, and that the actual limit is simply based on your system.</p>
  
  <p>Note: I tried saving and closing, then re-opening the worksheet after some iterations, as suggested in here: <a href="http://support.microsoft.com/kb/210684/en-us" rel="nofollow">http://support.microsoft.com/kb/210684/en-us</a>. It did not solve the problem.</p>
  
  <p>Anyone have any ideas on how to resolve this problem?</p>