I have an excel macro that I'm running. The code does everything I want except that after about 200 iterations VB will run out of memory and I'll get an "automation error". I'm using the internet explorer object within my code. My code opens a web page within a browser, refreshes the page, clears browser cache, closes the web browser and then repeats these operations in a loop. Please don't ask why it does this; it's important to me that this works. After about 200 iterations VB will say that there is an "automation error; unspecified error". I think the problem is that I'm re-instantiating the internet explorer object every time the loop runs. I have pasted the code below. Can someone please offer some suggestions as to how I can run the loop as long as I want without running out of memory? THE CODE HAS TO OPEN AND CLOSE A WEB BROWSER REPEATEDLY until I decide to click a button and end the process.
Expand|Select|Wrap|Line Numbers
- Private Sub cmdProcess1_Click()
- Dim flag As Boolean
- flag = True
- Call Clear_Cache
- Do While flag = True ''will keep opening web page while flag is true
- Call Clear_Cache
- Set iexplore2 = CreateObject("InternetExplorer.Application")
- iexplore2.Visible = True
- iexplore2.Navigate URL:="http://www.google.com" ''load web page
- Do While iexplore2.ReadyState <> 4 ''wait till web page finishes loading
- DoEvents
- Loop
- Call Clear_Cache ''clear browser cache
- iexplore2.Quit ''close web page
- Set iexplore2 = Nothing ''reset to preserve memory but THIS DOES NOT WORK!!!
- Loop
- End Sub
- Private Sub cmdStop_Click()
- Call Clear_Cache
- End
- End Sub
- Private Sub cmdProcess2_Click()
- Dim flag As Boolean
- flag = True
- Do While flag = True ''will keep opening web page while flag is true
- Set iexplore = CreateObject("InternetExplorer.Application")
- iexplore.Visible = True
- iexplore.Navigate URL:="http://www.google.com" ''load web page
- Do While iexplore.ReadyState <> 4 ''wait till web page finishes loading
- DoEvents
- Loop
- Call Clear_Cache ''clear browser cache
- iexplore.Refresh 'refresh banner page
- Do While iexplore.ReadyState <> 4 ''wait till refresh finishes loading
- DoEvents
- Loop
- Call Clear_Cache ''clear cache after refresh
- iexplore.Quit ''close web page
- Set iexplore = Nothing ''reset to preserve memory but THIS DOES NOT WORK!!!
- Loop
- End Sub
- Sub Clear_Cache()
- Call Clear_Temp_Files
- Call Clear_Cookies
- Call Clear_History
- Call Clear_Form_Data
- Call Clear_Saved_Passwords
- Call Clear_All
- End Sub
- Sub Clear_Temp_Files()
- Shell ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 ")
- End Sub
- Sub Clear_Cookies()
- Shell ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
- End Sub
- Sub Clear_History()
- Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
- End Sub
- Sub Clear_Form_Data()
- Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16"
- End Sub
- Sub Clear_Saved_Passwords()
- Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
- End Sub
- Sub Clear_All()
- Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
- End Sub
- Sub Clear_Clear_Add_ons_Settings()
- Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
- End Sub