gpt4 book ai didi

vba - objProcess.Terminate 未找到

转载 作者:行者123 更新时间:2023-12-04 21:53:29 26 4
gpt4 key购买 nike

试图杀死 InternetExplorer:

Sub IE_kill()

Dim objWMI As Object, objProcess As Object, objProcesses As Object
Set objWMI = GetObject("winmgmts://.")
Set objProcesses = objWMI.ExecQuery( _
"SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")

For Each objProcess In objProcesses
If Not objProcess Is Nothing Then
hh = objProcesses.Count ' 1
objProcess.Terminate ' Here is Error Not Found
If Err.Number <> 0 Then
Else
'DisplayErrorInfo
Exit For
End If
End If
Next
Set objProcesses = Nothing: Set objWMI = Nothing


End Sub

但有时会在 objProcess.Terminate 上出错未找到
如何解决问题?错误捕获没有帮助。在错误恢复下,下一步不能作为错误引发工作。

最佳答案

我已经尝试过对您的代码进行这种修改(对于 MS Edge),到目前为止它工作了大约 3 次:

Option Explicit

Sub KillIE()

Dim objWMI As Object, objProcess As Object, objProcesses As Object
Set objWMI = GetObject("winmgmts://.")
Set objProcesses = objWMI.ExecQuery("SELECT * FROM Win32_Process")

For Each objProcess In objProcesses
If Not objProcess Is Nothing Then
If InStr(1, UCase(objProcess.Name), "EDGE") > 0 Then
Debug.Print objProcess.Name
objProcess.Terminate
If Not Err.Number <> 0 Then
Exit For
End If
End If
End If
Next
End Sub

你可以试试看 objProcess.Name , 在它给出错误之前。考虑更换 "EDGE"INTERNETEXPLORERIEXPLORER .

关于vba - objProcess.Terminate 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731486/

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