当大量操作Excel时,总有大量的Excel的进程没有被关掉;
下面的方法可以帮助你操作完一次Excel,就能将其及时的关闭。
Dim objECAToolApplication As ECAToolApplication = ECAToolApplication.Instance Dim objExcelApp As Excel.Application = New Excel.Application Dim objExcelBook As Excel.Workbook = Nothing Dim objExcelSheet As Excel.Worksheet = Nothing If Not objExcelSheet Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelSheet) objExcelSheet = Nothing End If If Not objExcelBook Is Nothing Then objExcelBook.Close() System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelBook) objExcelBook = Nothing End If objExcelApp.Application.IgnoreRemoteRequests = False If Not objExcelApp Is Nothing Then objExcelApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objExcelApp = Nothing End If Dim myProcesses As Process() myProcesses = Process.GetProcessesByName("Excel") For Each myProcess As Process In myProcesses startTime = myProcess.StartTime If startTime > beforeTime And startTime < afterTime Then myProcess.Kill() End If Next