我遇到一个问题,其中一个位于共享 Excel 2010文件的网络已成功打开并从VB.net进行编辑,但当我用Excel.Application.Quit()关闭它时,窗口本身关闭,但EXCEL.EXE进程仍然打开。
作为一种解决方法,如果Process.StartTime与我打开excel的时间匹配,我会终止进程,但这可以 a)不要杀死任何以前错过的excel进程 b)可以杀死完全不同的工作簿......
Dim xlp() As Process = Process.GetProcessesByName("EXCEL")
For Each Process As Process In xlp
If Process.StartTime >= datestart And Process.StartTime <= dateEnd Then
Process.Kill()
End If
Next
我尝试将表单设置为已保存,但它没有帮助。但是,如果我取消共享excel表,那么当工作簿,然后窗口关闭时,进程也会正常死亡。
Dim xlApp As Excel.Application = Nothing
Dim xlWorkBook As Excel.Workbook = Nothing
Dim xlWorkSheet As Excel.Worksheet = Nothing
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(Excel_path)
xlWorkSheet = xlWorkBook.Worksheets(sheetName)
' whitchcraft here
xlWorkBook.Close(SaveChanges:=True)
xlApp.Quit()
releaseObject(xlWorkSheet)
releaseObject(xlWorkBook)
releaseObject(xlApp)
请缓解我的痛苦......