vba - objProcess.Terminate 未找到

标签 vba excel internet-explorer

试图杀死 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/

相关文章:

java - 连接到 Excel 时出现 "Unable to recognize OLE stream"异常

html - 让可折叠导航栏在 Internet Explorer 中工作的问题

javascript - 取消移动 IE 11 上事件的滚动

c# - 代码运行时退出 Interop 控制的 Excel

css - IE7 在同一个元素上 float 和清除

function - VBA:Excel 范围总是显示为空?

excel - 将数组从 VBA 传递到 VB.NET

excel - .Range 和 .InsertShift 在新工作表上复制表格 : overwriting data

sql-server - access-SQL 传递查询(创建 SP)错误

excel - VBA:有没有办法获取/读取模块属性?