launch Excel from WinForm app

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?
 
G

Guest

Have you tried
myWorkBook.Close(false,Type.Missing,Type.Missing);
Marshal.ReleaseComObject(myWorkBook);
 
B

BrenB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top