473,473 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB macro with internet explorer object runs out of memory

1 New Member
Hi All,

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
  1.  
  2. Private Sub cmdProcess1_Click()
  3.  
  4. Dim flag As Boolean
  5. flag = True
  6. Call Clear_Cache
  7.  
  8. Do While flag = True ''will keep opening web page while flag is true
  9.  
  10. Call Clear_Cache
  11. Set iexplore2 = CreateObject("InternetExplorer.Application")
  12. iexplore2.Visible = True
  13. iexplore2.Navigate URL:="http://www.google.com" ''load web page
  14.  
  15.     Do While iexplore2.ReadyState <> 4 ''wait till web page finishes loading
  16.         DoEvents
  17.     Loop
  18.  
  19. Call Clear_Cache ''clear browser cache
  20. iexplore2.Quit ''close web page
  21. Set iexplore2 = Nothing ''reset to preserve memory but THIS DOES NOT WORK!!!
  22.  
  23. Loop
  24.  
  25. End Sub
  26.  
  27. Private Sub cmdStop_Click()
  28.  
  29. Call Clear_Cache
  30.  
  31. End
  32.  
  33. End Sub
  34.  
  35. Private Sub cmdProcess2_Click()
  36.  
  37. Dim flag As Boolean
  38. flag = True
  39.  
  40. Do While flag = True ''will keep opening web page while flag is true
  41. Set iexplore = CreateObject("InternetExplorer.Application")
  42. iexplore.Visible = True
  43.  
  44.  
  45. iexplore.Navigate URL:="http://www.google.com" ''load web page
  46.  
  47.     Do While iexplore.ReadyState <> 4 ''wait till web page finishes loading
  48.         DoEvents
  49.     Loop
  50.  
  51. Call Clear_Cache ''clear browser cache
  52.  
  53. iexplore.Refresh 'refresh banner page
  54.  
  55.     Do While iexplore.ReadyState <> 4 ''wait till refresh finishes loading
  56.         DoEvents
  57.     Loop
  58.  
  59. Call Clear_Cache  ''clear cache after refresh
  60.  
  61. iexplore.Quit ''close web page
  62. Set iexplore = Nothing ''reset to preserve memory but THIS DOES NOT WORK!!!
  63. Loop
  64.  
  65. End Sub
  66.  
  67. Sub Clear_Cache()
  68.  
  69. Call Clear_Temp_Files
  70. Call Clear_Cookies
  71. Call Clear_History
  72. Call Clear_Form_Data
  73. Call Clear_Saved_Passwords
  74. Call Clear_All
  75.  
  76. End Sub
  77. Sub Clear_Temp_Files()
  78. Shell ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 ")
  79. End Sub
  80. Sub Clear_Cookies()
  81. Shell ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
  82. End Sub
  83.  
  84. Sub Clear_History()
  85. Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
  86. End Sub
  87.  
  88. Sub Clear_Form_Data()
  89. Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16"
  90. End Sub
  91.  
  92. Sub Clear_Saved_Passwords()
  93. Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
  94. End Sub
  95.  
  96. Sub Clear_All()
  97. Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
  98. End Sub
  99.  
  100. Sub Clear_Clear_Add_ons_Settings()
  101. Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
  102. End Sub
  103.  
  104.  
May 20 '10 #1
0 1403

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
0
by: Roshan Jayalath | last post by:
Hi all, Can someone tell me how to create the Pocket Internet explorer object and assign it into a variable so I can use it as a web browser control within a Vb.net form. SET loPIE =...
11
by: dhplank | last post by:
Hello everyone, I've developed a calendar program in javascript, and up until now I've done most of my testing using Mozilla and Firefox. Everything works fine, but when I try to use Internet...
6
by: tinkerman | last post by:
Hello net friends, I need to automate Internet Explorer in a very simple way. I need to: 1. press refresh (F5) on the currently loaded website. 2. press END button. 3. Click a button...
10
by: Edlueze | last post by:
I am developing some Data Access Pages (DAP) using Microsoft Access 2003 on Microsoft Windows XP. When I try to open these pages (located on my C: drive), the display of the data access page is...
7
by: Stewart Saathoff | last post by:
Hello, Does anyone know how to open an Internet Explorer URL with a specified Path when someone clicks a URL?
16
by: VBSome | last post by:
As far as I understand there is no native VB.NET equivalent of the VB6 Web browser control. There are some things I can play with HTML wise, but none do what I really need to do (which is...
1
by: Apu Nahasapeemapetilon | last post by:
Hello and thank you in advance for your help. Can anyone think of a reason why this code would work properly on one PC, but not another? I've got a System.Windows.Forms.UserControl that...
11
by: GHUM | last post by:
Hello, I created some rather complex Intranet Application, using lots of JavaScript, DOM-Maninpulation and XMLHTTPRequest communication. I developed on FireFox, with the excellent firebug ......
26
by: Prisoner at War | last post by:
Hi, All: I have a JavaScript search engine that always causes MSIE 7 to do a top-of-page security "warning" (that top-of-page-bar, and not an "alert" )...but other websites' JavaScripts do not...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.