View Single Post
  #6 (permalink)  
Old December 6th, 2013, 04:19 AM
RedDotVasilyev RedDotVasilyev is offline
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Unable to open excel file thru vb.net

Hi, just to add to a caveatashish's answer, when you are finished with your spreadsheet’s tasks it is not enough to close the file. You need to release every COM object which was created and quit the application, you can read more about this on this discussion:
Code:
xlApp.Quit()
Marshal.ReleaseComObject(xlWorkSheet)
Marshal.ReleaseComObject(xlWorkBook)
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
Also you can try this simpler approach with a help of this VB.NET library, it has an easy to use API for reading an excel file in .NET and you will not have to bother with releasing the COM objects from the memory.
Code:
Dim xlWorkBook As ExcelFile = ExcelFile.Load("c:\test1.xlsx")
Dim xlWorkSheet As ExcelWorksheet = xlWorkBook.Worksheets("sheet1")
Reply With Quote