Close all IE Browser windows with VBA

tx12345

Board Regular
Joined
Aug 28, 2006
Messages
165
Hi

I have been using

ie.Quit
Set IE = Nothing

but that only closes one browser window. however, sometimes a pop up window shows up and is still left on the desktop. just wondering if there is a command to say

'ie.closeall'

or something like that

tx
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
Well there is always NateO's sledgehammer... But I would use this with caution, it will kill ALL internet explorer windows:

Code:
Option Explicit
Sub IE_Sledgehammer()
    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
        Call objProcess.Terminate
    Next
    Set objProcesses = Nothing: Set objWMI = Nothing
End Sub
 

davidam

Active Member
Joined
May 28, 2010
Messages
452
Nice one Oorang! All kinds of web-scraping activities get bogged down as IE takes more and more resources...an occasional loop to "IE_Slegehammer" and the problem is solved. Thank you!
 

davidam

Active Member
Joined
May 28, 2010
Messages
452
I see credit is due to NateO originally...good one. One thing that happens if you are looping through many times is that a program will hang as it seems unable to restart IE. I put an: Application.Wait (Now + Time Value("0:00:03")) line at the end of IE+Sledgehammer and it seems to have resolved this problem completely.
 

shreyasfifa

New Member
Joined
Aug 9, 2016
Messages
1
The Sledgehammer kills the IE process but then my VBA code just hangs after that. How do I make it loop?

With ie
.Visible = False

For j = 2 To i

If j = 4 Then
Call IE_Sledgehammer
End If
.navigate "http://google.com/gp/product/" & ThisWorkbook.Sheets(1).Cells(j, 1)
 

Watch MrExcel Video

Forum statistics

Threads
1,113,811
Messages
5,544,451
Members
410,612
Latest member
MrACED
Top