After restart of a Windows Forms application (crashed due to severe error) how can I reestablish connection to a previously initiated Excel instance which is still existing and
contains important data for the restarted forms application ?
I have a VB.net based Windows forms application which is using Excel in the background for calculations.
I am starting Excel with
Public Excel_App As Microsoft.Office.Interop.Excel.Application
Public Excel_WB As Microsoft.Office.Interop.Excel.Workbook
Public Excel_WS As Microsoft.Office.Interop.Excel.Worksheet
Dim Filepath As String
Excel_App = New Microsoft.Office.Interop.Excel.Application
Excel_App.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlNormal
Excel_App.Visible = False
Excel_App.DisplayStatusBar = False
Excel_WB = Excel_App.Workbooks.Open(FilePath)
Excel_WS = Excel_WB.Worksheets("Data")
<Processing of data on the Excel sheet>
When the foems application is restatred after a crash the code is creating a new instance of Excel which then opens the same file, however this time in read only mode (because the previous instance is still alive).
I like to identify such a case and reestablish connection to the previous Excel instance instead of creating a new one.
I will appreciate any hint on how to do this.