Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net certain excel file left running

Status
Not open for further replies.

asibin2000

Programmer
Dec 10, 2007
22
US
So I have a fairly robust VB.NET winform that opens excel and collects data.

The problem is that I am still testing it, and trying to debug it can be problematic.

So i'm asking if someone has a code snippet for VB.net that would kill any extraneous excel.exe running..

So the programs opens a specific excel sheet, and right now i am trying to debug a business process but when the program crashes it leaves several instances of excel.exe running, so i have to manually delete these within ctrl alt delete.

I'm looking for a little function that i'd place at the start of my program that would clear out all those stuck excel.exe's

Once I get all the bugs out of the my program it wont be an issue because I have a good close function.

Thanks,

Asi
 
I had such experience. Some experts (after googling out) suggest these lines:
Code:
        oExcel.Workbooks.Close()
        oExcel.Quit()
        ReleaseComObject(oExcel)
        oExcel = Nothing

But it didn't work.
So I switch to manually close the left over Excel application.
Code:
      Dim exprs As Process() = Process.GetProcessesByName("EXCEL")
      For Each ep As Process In exprs
        If ep.MainWindowTitle = "" Then
          ep.Kill()
        End If
      Next

Good luck.
 
mansii,

If you use the code to iterate through every process that is Excel.exe, then what happens if I open Excel to work on a project and I run your app at the same time? Now let's say I didn't save. Your app just hosed the last hour of work I just did.

objExcel.Quit is the correct line to exit out of Excel, that you instantiated (not the user's open session), properly.
 
Okay, I just saw the ep.MainWindowTitle = "" catch, but even still. It's not wise to close Excel that way. Use .Quit.
 
As I mentioned before, the Quit method didn't work for me (on WinXP machine, Office 2003).
Or I might be missing something in my code.

Anyways, the Kill method did the job well for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top