Making an IE Window the focus for Excel VBA

E

expect_ed

I want to extract data from a web page which is called with a Post method
which makes it impossible for me to indicate the URL, so I call the previous
page, where there is a link for the page I want and Sendkey Tab to the link
and Sendkey Enter. This brings up the page I want in a new window.

The problem is that page takes a while to load, and if I use:
Do While IE.readystate <> 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop

it does not work, apparently because Excel is still looking at the parent
window.

I tried using:
Dim IES As SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer

For Each IE In IES

If IE.LocationURL = "http://server.myURL.com:8080/requests.do" Then
Do While IE.readystate <> 4
DoEvents
Loop

Do While IE.busy = True
DoEvents
Loop

IE.Visible = True
Set IE = IE
Exit For
End If

Next

VBA seems to find the right window but when it finds it the window is still
loading data and the routine falls through to the next section which reads
the data and it errors out because table 300 is not there yet.

For now I'm using a sub pause work around to delay several seconds before
trying to find and read the new page, but I would like to get Excel to point
to the correct window so that the normal Do While code waits just long
enough, due to the variability in loading the page and because I am looping
through several hundred pages.

Any help greatly appreciat
ed
 
J

Joel

try combining the two do loops. You can't tell which is finishing 1st

Do While IE.readystate <> 4 and _
IE.busy = True

DoEvents
Loop
 
E

expect_ed

Do that happen sequentially?
In any case I think it falls through both of them becuase the focus is on
the parent window while the child is still busy opening.
ed
 

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