So I have a little gui that will read a given spreadsheet and list all the "valid" sheets. This happens when a user presses a button.

here is my code:

VB.NET Code:
  1. Private Sub bttnScanWorksheets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnScanWorksheets.Click
  2.         If System.IO.File.Exists(TextBox1.Text) = True Then
  3.  
  4.             'Clear checkbox area
  5.             CheckedListBox1.Items.Clear()
  6.  
  7.             ' Open excel
  8.             Dim excelapp As Excel.Application
  9.             Dim WB As Excel.Workbook
  10.             Dim WS As Excel.Worksheet
  11.             excelapp = New Excel.Application
  12.             WB = excelapp.Workbooks.Open(TextBox1.Text)
  13.             Dim CheckValid As Boolean
  14.             Dim SheetsAdded As Boolean = False
  15.  
  16.             ' Cycle through each sheet
  17.             For Each WS In WB.Worksheets
  18.                 Try
  19.                     CheckValid = True
  20.                     If WS.Range("B4").Value.ToString <> "Employee Name:" Then
  21.                         CheckValid = False
  22.                     End If
  23.                     If WS.Range("H4").Value.ToString <> "Week No.:" Then
  24.                         CheckValid = False
  25.                     End If
  26.                     If WS.Range("F8").Value.ToString <> "Cost" Then
  27.                         CheckValid = False
  28.                     End If
  29.  
  30.                     ' Add the sheet to the list
  31.                     If CheckValid = True Then
  32.                         CheckedListBox1.Items.Add(WS.Name) ' Populate the checkbox area
  33.                         SheetsAdded = True
  34.                     End If
  35.                 Catch ex As NullReferenceException ' Catch errors that arrise from merged cells.
  36.                 Catch ex As Exception
  37.                     MsgBox(ex.ToString) ' any other errors will be caught here
  38.                 End Try
  39.             Next
  40.  
  41.             If SheetsAdded = False Then
  42.                 MsgBox("There were no valid sheets in this workbook.")
  43.             End If
  44.  
  45.             ' Close Excel
  46.             WB.Close()
  47.             excelapp.Quit()
  48.             Marshal.ReleaseComObject(excelapp)
  49.             excelapp = Nothing
  50.             GC.Collect()
  51.             GC.WaitForPendingFinalizers()
  52.             GC.Collect()
  53.         Else
  54.             MsgBox("That file does not exist")
  55.         End If
  56.     End Sub

The problem is that Excel.exe doesn't quit until the program closes for some reason. This causes the spreadsheet to remain read only until the program is closed.

Any ideas why excel isn't closing properly?