title: declare/open excel file in vb.net
body: <p>I've been trying for a while to declare or to open a excel sheet in vb.net.
  I already read <a href="https://stackoverflow.com/questions/1464281/excel-file-in-vb-net">excel file in vb.net</a>
  and other links but it doesn't work.</p>
  
  <p>I added Microsoft Excel 12.0 Object Library.
  I included:</p>
  
  <pre><code>Imports Microsoft.VisualBasic
  Imports System.Net.Mime.MediaTypeNames
  Imports Microsoft.Office.Interop 
  </code></pre>
  
  <p>I want to declare / open the excel file in a module:</p>
  
  <pre><code>Public Module postleitzahlen_array
  
  Dim myarray As String
  
  Dim xlApp As Excel.Application
  xlApp = New Excel.ApplicationClass ' here is the error, XlApp "has to be declared"
  </code></pre>
  
  <p>Can someone help me?</p>
  
  <p>EDIT:</p>
  
  <p>Okay, i noticed that i use excel 2007, and there is a difference - now I'm using follwing code from <a href="http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm" rel="nofollow noreferrer">http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm</a></p>
  
  <pre><code>Sub test()
          Dim xlApp As Excel.Application
          Dim xlWorkBook As Excel.Workbook
          Dim xlWorkSheet As Excel.Worksheet
  
          Dim misValue As Object = System.Reflection.Missing.Value
  
          xlApp = New Excel.ApplicationClass
          xlWorkBook = xlApp.Workbooks.Add(misValue)
          xlWorkSheet = xlWorkBook.Sheets("sheet1")
          xlWorkSheet.Cells(1, 1) = "http://vb.net-informations.com"
          xlWorkSheet.SaveAs("D:\vbexcel.xlsx")
  
          xlWorkBook.Close()
          xlApp.Quit()
  
          releaseObject(xlApp)
          releaseObject(xlWorkBook)
          releaseObject(xlWorkSheet)
  
          MsgBox("Excel file created , you can find the file c:\")
      End Sub
  
  
      Private Sub releaseObject(ByVal obj As Object)
          Try
              System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
              obj = Nothing
          Catch ex As Exception
              obj = Nothing
          Finally
              GC.Collect()
          End Try
      End Sub
  </code></pre>
  
  <p>but I get an error in <code>xlWorkSheet = xlWorkBook.Sheets("sheet1")</code> saying "(Exception by HRESULT: 0x8002000B (DISP_E_BADINDEX))</p>
  
  <p>Edit2:
  I use a german excel, so "sheet1" throws an error --> "tabelle1" is the right word :)</p>