title: Handle the event "Excel is closing"
body: <p>I have a vb .net app which opens an Excel file and puts values in it. But if the user (who I have to assume is extremely dumb :) ), closes the workbook, next time my app will try to put a value to the file, it will show an error since there is no excel file open.</p>
  
  <p>How can I either prevent excel from being closed, or disable the buttons when excel is closed?</p>
  
  <p>I'm working with Excel 2003 on Windows 7</p>
  
  <p>EDIT: Here is the code to open Excel</p>
  
  <pre><code>Private Sub Open_button_Click(sender As Object, e As EventArgs) Handles Open_button.Click
  
  
      OpenFileDialog1.FileName = ""
      OpenFileDialog1.Filter = "Excel files (*.xls)|*.xls"
      OpenFileDialog1.ShowDialog()
      filePath = OpenFileDialog1.FileName
      If System.IO.File.Exists(filePath) Then
          oExcel = CreateObject("Excel.Application")
          oExcel.Visible = True
          oBook = oExcel.Workbooks.Open(filePath)
  
  
          oSheet = oBook.WorkSheets(1)
          oExcel.Sheets(1).Select()
          oExcel.ScreenUpdating = True
          xlDown = Microsoft.Office.Interop.Excel.XlDirection.xlDown
          xlUp = Microsoft.Office.Interop.Excel.XlDirection.xlUp
          Me.Activate()
  
      End If
  End Sub
  </code></pre>