0

My vb.net code is used to generate an Excel spreadsheet. Once the Excel file is created and both the program and Excel is closed, a phantom process remains. I've tried the following:

    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim xlWorkSheet2 As Excel.Worksheet
    Dim xlRange As Excel.Range

    'Write data to Excel here

    Marshal.ReleaseComObject(xlApp)
    Marshal.ReleaseComObject(xlWorkBook)
    Marshal.ReleaseComObject(xlWorkSheet)
    Marshal.ReleaseComObject(xlWorkSheet2)

I've also tried some other things where the process is killed programmatically. What I'd like to do is to keep the Excel workbook that was generated by the code opened and kill the phantom process without killing the opened spreadsheet. For some reason, the hidden process is not visible while Excel is still opened but after manually closing Excel a process remains opened. Any suggestions?

Mike S
  • 33
  • 1
  • 1
  • 5
  • [This thread](https://stackoverflow.com/questions/14222501/excel-process-not-closing-in-vb-net) may provide some info – cybernetic.nomad Jul 06 '18 at 19:30
  • Thanks. Yes I saw that thread, but I think the example provided kills all instances of Excel. I'm not sure why a phantom process remains. It's a little baffling. – Mike S Jul 06 '18 at 19:43
  • 1
    I found a solution that works. The following thread fixed the problem -->https://stackoverflow.com/a/1611178/9980075 – Mike S Jul 06 '18 at 19:47
  • 1
    Yes, I think so. Thank you. – Mike S Jul 09 '18 at 15:58

1 Answers1

0

I have been through a similar nightmare in the past where a server application was leaving these excel.exe instances behind.

The way I solved this personally was to use a windows scheduled job to execute a batch file that used the TASKKILL /IM Excel command at a sensible interval - not elegant but it got us out of some hot water.

If you're not stuck with pre-2007 excel (xls) formats, i'd suggest you take a look at the excellent (no pun intended) ExcelDataReader and optionally ExcelDataReader.Dataset nuget packages - these are brilliant and great for free commercial use.

There's a brief tutorial (in c#) here which wouldn't take much to rewrite in vb.

If you can't move to xlsx just yet, and it's data more than formatting you're interested in, you might want to check out the CSVHelper Nuget package by Josh Close.

I've used both of these with great ease and can confirm they do the job.

Let me know if these are helpful suggestions.

dbl4k
  • 71
  • 6