I apologize for my ignorance, but my fundamental understanding of scripting is quite limited to non existent. Anyway, I have to go back to the mountain for some help so here is my problem.
I have a script I'm working on which will use 'for' statement to loop through about 500 websites. On each website, it will extract data needed to loop through (nested 'for' statement) about 5 more websites to pull information I'm looking for. Instead of making it to 500, it seems to get stuck at finding ready state after only about 6 of them. I have changed the order of the 500 and it does not seem to be a particular website. It also hasn't gotten stuck on the nested 'for' statement, despite running ~5x more times. The procedures and sites are a little different as you will see. The script just keeps grinding. When I go to task manager and kill the iexplore.exe, the following message pops up when I run it through text pad. Note, I highlightt the actual line item in the alarm text in the script.
Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'ReadyState'
Any ideas here would be appreciated while i think more on it.
myVars_s = "~500,comma,separated,strings"
myVars = split(myVars_s,",")
num_myVars = UBound(myVars)
For m = 0 to num_myVars
theURL = "www.website.prefix.com/" & myVars(m)
set ie = CreateObject("InternetExplorer.Application")
ie.Navigate("http://" & theURL)
Do until ie.ReadyState = 4 <---this is line called out by alarm text
WScript.Sleep 100
Loop
With ie.document
set theTables = .all.tags("table")
(find correct table and extract list of ~5 more strings = myStrings)
myStrings_s = "~15,comma,separated,strings"
myStrings = split(myStrings_s,",")
num_myStrings = UBound(myStrings)
For j = 0 to num_myStrings
myOtherURL = "www.anotherwebsite.prefix.com" & myStrings(j)
set ie = createobject("internetexplorer.application")
ie.navigate myOtherURL
ie.visible = 1
do until ie.readystate = 4
wscript.sleep 100
loop
text = ie.document.body.innerTEXT
(use inStr(text) feature to extract the text I want)
ie.quit
Next
ie.Quit
End With
Next
I think you run out of memory, can you check how many iexplorer.exe
you have in task manager?
In some broken Windows System, your IE.Quit will fail...
also note the following points:
for outer loop and for inner loop
use different variable name for the IE object
outer loop: ie
, inner loop: ie2
you used ie.quit
inside the with ie.document
block, might cause problem?
According to this post, you can try removing the Sleep
statement inside the Do
Loop
I would usually use
Do While IE.Busy
Loop
Do While IE.readyState <> 4
Loop
EDIT:
For IE.Quit NOT able to kill all iexplorer.exe, maybe due to this reason, To ensure there's no memory leakage, you can rearrange your code AND force kill all IE instance using method in Googling VBA Kill IE
You should rearrange like this
for i = XXXX ' OUTER FOR LOOP
set IE = 'outer URL
with IE
' assgin the param. into variables
start = IE. XXX
end = IE.YYY
end with
IE.quit
for j = start to end ' INNER FOR LOOP
set IE = ' inner url
'loop inner IE
with IE
end with
IE.quit
next j
next i