launch Excel from WinForm app

  • Thread starter Thread starter BrenB
  • Start date Start date
B

BrenB

I want to open an Excel doc from my .NET 2.0 WinForm application.

I have a list of UNC path names of Excel documents a user might want
to open.

The way I'm doing it now works, but when the user closes Excel, it is
still running; I can see it in the list of processes in TaskManager.

My WinForm app open the document this way:

Dim pathname As String = ListBox1.SelectedItem.ToString()
Dim excelApp As Excel.Application
excelApp = New Excel.Application()
excelApp.Workbooks.Open(pathname)
excelApp.Visible = True
excelApp = Nothing

Even though I am setting excelApp to nothing, my WinForm app is
holding on to Excel after the user closes it.

Is there a better approach to opening Excel so that it will close when
the user closes the Excel window?
 
Have you tried
myWorkBook.Close(false,Type.Missing,Type.Missing);
Marshal.ReleaseComObject(myWorkBook);
 
Thank you both, Robbe and Mike, for responding to my post. Your
suggestions worked for me.

I nulled all my objects after calling the ReleaseComObjects method on
them.

I did not close the workbooks or quit the app in my code. When I
closed Excel using its user interface, I saw its process end in Task
Manager.

I appreciate the help.

Bren
 
Back
Top