Closing Excel from VB.Net?

kentlip

New member
Joined
Mar 18, 2022
Messages
1
Programming Experience
1-3
Why does it leave some Excel zombie processes running?
---------------------------------------------
Imports Microsoft.office.interop
Imports System.IO

Public Class Form1

Dim xlApp = New Excel.Application
Dim xlWorkBook = xlApp.Workbooks.Open("C:\Book1.xls")
Dim xlSheet = xlWorkBook.Worksheets(1)

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing

MsgBox("Form Closing")
xlApp.visible = True
xlApp.Quit()

' CLEAN UP. (CLOSE INSTANCES OF EXCEL OBJECTS.)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) : xlSheet = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook) : xlWorkBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) : xlApp = Nothing

End Sub
 
Top Bottom