Terminating all explorer instances via VBA - Excel

Viewed 2263
Private Sub CommandButton1_Click()
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
    objProcess.Terminate
Next

Set objProcesses = Nothing
Set objWMI = Nothing

Unload WebForm

End Sub    

Trying to use this as a way to close out all instances of Explorer before running some functions that retrieve data from web based servers, but am running into an issue when it attempts to close out an open browser with multiple tabs. If the user has only one IE window (one tab) open, then it closes it just fine and moves on; if these user has multiple windows open separately (not tabbed in one window), then it closes them all just fine and moves on; but for some reason, if one window is open with multiple tabs, then I get run-time error '-2147217406 (80041002)': "Not found". Any help working through this would be greatly appreciated.

2 Answers
Related