Note that there are some explanatory texts on larger screens.

plurals
  1. POReleasing Excel after using Interop
    primarykey
    data
    text
    <p>I've read many post looking for my answer, but all are similar to this: <a href="https://stackoverflow.com/questions/1610743/reading-excel-files-in-vb-net-leaves-excel-process-hanging">Reading excel files in vb.net leaves excel process hanging</a></p> <p>My problem is that I don't quit the app...</p> <p>The idea is this:</p> <p>If a User has Excel Open, if he has the file I'm interested in open... get that Excel instance and do whatever I want to do...</p> <p>But I don't to close his File after I'm done... I want him to keep working on it, the problem is that when he closes Excel... The process keeps running... and running... and running after the user closes Excel with the X button...</p> <p>this is how I try to do it</p> <p>This piece is used to know if he has Excel open, and in the For I check for the file name I'm interested in.</p> <pre><code> Try oApp = GetObject(, "Excel.Application") libroAbierto = True For Each libro As Microsoft.Office.Interop.Excel.Workbook In oApp.Workbooks If libro.Name = EquipoASeccionIdSeccion.Text &amp; ".xlsm" Then Exit Try End If Next libroAbierto = False Catch ex As Exception oApp = New Microsoft.Office.Interop.Excel.Application End Try </code></pre> <p>here would be my code... if he hasn't Excel open, I create a new instance, open the file and everything else.</p> <p>My code ends with this:</p> <pre><code>If Not libroAbierto Then libroSeccion.Close(SaveChanges:=True) oApp.Quit() Else oApp.UserControl = True libroSeccion.Save() End If System.Runtime.InteropServices.Marshal.FinalReleaseComObject(libroOriginal) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(libroSeccion) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(origen) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(copiada) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp) libroOriginal = Nothing libroSeccion = Nothing oApp = Nothing origen = Nothing copiada = Nothing nuevosGuardados = True </code></pre> <p>So you can see that, if I opened the file, I call oApp.Quit() and everything else and the Excel Process ends after a few seconds (maybe 5 aprox.)</p> <p>BUT if I mean the user to keep the file open (not calling Quit()), Excel process keeps running after the user closes Excel with the X button.</p> <p>Is there any way to do what I try to do?? Control a open instance of excel and releasing everything so when the user closes it with the X button, the Excel Process dies normally???</p> <p>Thanks!!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload