gpt4 book ai didi

Excel 实例没有在任务管理器 VB.net 中被杀死

转载 作者:行者123 更新时间:2023-12-04 20:58:07 26 4
gpt4 key购买 nike

按钮执行结束后,任务管理器中的 Excel 实例 (excel.exe) 不会被杀死。

Private Sub Extract_Click(sender As Object, e As EventArgs) Handles Extract.Click
Dim xlApp As New Excel.Application
Dim wbXLsource As Excel.Workbook
Dim wbXLtarget As Excel.Workbook
Dim shXLsource As Excel.Worksheet
Dim shXLtarget As Excel.Worksheet
Dim datestart As Date = Date.Now
wbXLsource = xlApp.Workbooks.Open(xlSourcePath)
wbXLtarget = xlApp.Workbooks.Open(xlTargetPath)
Dim dateEnd As Date = Date.Now
End_Excel_App(datestart, dateEnd)
End Sub

Private Sub End_Excel_App(datestart As Date, dateEnd As Date)
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()
Exit For
End If
Next
End Sub

我也尝试使用垃圾收集器概念,但只有在关闭应用程序后,excel 实例才会被杀死。按钮执行结束后,我需要关闭 excel 实例(excel.exe)

最佳答案

使用此代码....我一直在使用它,每次都会关闭

For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
If proc.MainWindowTitle.Trim() = "" Then
proc.Kill()
End If
Next

如果你有一个 Try Catch 错误处理程序......
Try

'stuff more stuff

Catch Ex as Exception

For Each Proc in System.......
......
Next
Finally
GC.Collect()
End Try

每次都有效。

关于Excel 实例没有在任务管理器 VB.net 中被杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42352140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com