ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Making an IE Window the focus for Excel VBA (https://www.excelbanter.com/excel-programming/428718-making-ie-window-focus-excel-vba.html)

expect_ed

Making an IE Window the focus for Excel VBA
 
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

joel

Making an IE Window the focus for Excel VBA
 
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




"expect_ed" wrote:

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


expect_ed

Making an IE Window the focus for Excel VBA
 
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

"Joel" wrote:

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




"expect_ed" wrote:

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



All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com