Handling internet explorer memory leaks from Excel VBA

W

Walter Briscoe

I use Internet Explorer (IE) (both 8 and 9) from Excel 2003 via VBA.
I run IE8 from Windows XP and IE9 from Windows Vista.
(IE10 and IE11 are incompatible with Vista.)
I make repeated use of an instance of IE with
Public IE As SHDocVw.InternetExplorer _
' Needs Tools/References/Microsoft Internet Controls

....
If IE Is Nothing Then
Set IE = CreateObject("InternetExplorer.Application.1")
End If
....

I need to download train fare information with about 400k accesses.

Windows Task Manager shows 2 images names ieexplore.exe - a small one
and a large one.
The memory used by the large one gradually increases until it seizes.
When it seizes, control is not given to Excel until there is manual
interaction.
On Vista, the failure is a message box after about an hour:
' Microsoft Windows
' Internet Explorer has stopped working
' A problem caused the program to stop working correctly. Windows will
' close the program and notify you if a solution is available.
' Close program

I coded the following recursive asynchronous function helpful.
It stops IE being used for more than 10 minutes.

Private Sub saveSingleFares()
If Not ActiveWorkbook.Saved Then
IE.Quit
Set IE = Nothing
ActiveWorkbook.Save
End If
Application.OnTime EarliestTime:=Now + TimeValue("00:10:00"), _
Procedure:="saveSingleFares"
End Sub

I will probably code something less brutal later.
I would prefer code to look at the IE memory usage
in making a decision on killing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top