R
Rob Kellow
Hello,
I have a VB.NET application that needs to open an Excel workbook. It runs
fine and when I have the Visible property set to true, everything appears to
work as it is supposed to (Excel opens, the workbook opens, processing works,
and the workbook and Excel close) but when I go to Task Manager the instance
of Excel is still running. If I run the program repeated times, there is an
instance of Excel running for each time I ran the VB application. Here is
the code I'm using to open and close Excel:
***************************************************
' class members
Dim excelApp As Excel.Application
Dim excelWb As Excel.Workbook
Private Sub openExcel()
Try
excelApp = New Excel.Application
excelApp.Visible = True
Catch ex As Exception
MessageBox.Show("Excel Open Exception:" + ex.Message, "Excel
Exception", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub closeExcel()
Try
excelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWb)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
excelWb = Nothing
excelApp = Nothing
Catch ex As Exception
MessageBox.Show("Excel Close Exception:" + ex.Message, "Excel
Exception", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
***************************************************
Any help would be greatly appreciated.
Thanks in advance,
Rob
I have a VB.NET application that needs to open an Excel workbook. It runs
fine and when I have the Visible property set to true, everything appears to
work as it is supposed to (Excel opens, the workbook opens, processing works,
and the workbook and Excel close) but when I go to Task Manager the instance
of Excel is still running. If I run the program repeated times, there is an
instance of Excel running for each time I ran the VB application. Here is
the code I'm using to open and close Excel:
***************************************************
' class members
Dim excelApp As Excel.Application
Dim excelWb As Excel.Workbook
Private Sub openExcel()
Try
excelApp = New Excel.Application
excelApp.Visible = True
Catch ex As Exception
MessageBox.Show("Excel Open Exception:" + ex.Message, "Excel
Exception", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub closeExcel()
Try
excelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWb)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
excelWb = Nothing
excelApp = Nothing
Catch ex As Exception
MessageBox.Show("Excel Close Exception:" + ex.Message, "Excel
Exception", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
***************************************************
Any help would be greatly appreciated.
Thanks in advance,
Rob