Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set a pop up window to focus? OverMyHead Excel Discussion (Misc queries) 1 February 9th 10 11:24 PM
How to catch the event when an Excel window gets focus? Andrew Excel Programming 4 March 9th 07 05:20 AM
Find/Replace in VBE takes focus off window Excel 2003 ward376 Excel Programming 0 January 18th 07 11:14 PM
keep focus & window steady Gunnar Johansson Excel Programming 2 June 7th 04 06:13 AM
Making the minimized Excel window icon flash AndyKB Excel Programming 1 April 15th 04 03:40 AM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"