How to check IE is ready

raychung666

New Member
Joined
Mar 29, 2008
Messages
20
I wanted to query a series of stocks from a website using the following routine. It seemed that the do loop couldn't check the ready status of ie. When I ran the macro, stock 2866 was skipped and only stock 13 was displayed. May be it was so fast that I couldn't see 2866 being displayed. When I ran it line by line, it was working fine. Was the following do loop a good way to check the status of ie?

Sub test5()
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www.quamnet.com/quote.action"
Do While ie.Busy And Not ie.ReadyState = 4
DoEvents
Loop
ie.document.forms(4)("stockcode").Value = "2866"
ie.document.forms(4).submit
Do While ie.Busy And Not ie.ReadyState = 4
DoEvents
Loop
ie.document.forms(4)("stockcode").Value = "13"
ie.document.forms(4).submit
Do While ie.Busy And Not ie.ReadyState = 4
DoEvents
Loop
'ie.Quit
'Set ie = Nothing
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Change 'And' in the Do While loops to 'Or', like this:
Code:
Sub test5()
    Const READYSTATE_COMPLETE = 4
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate "http://www.quamnet.com/quote.action"
    
    'Original
    'Do While ie.Busy And Not ie.ReadyState = 4: DoEvents: Loop

    Do While ie.busy Or Not ie.readystate = READYSTATE_COMPLETE: DoEvents: Loop
    
    ie.document.forms(4)("stockcode").Value = "2866"
    ie.document.forms(4).submit
    
    Do While ie.busy Or Not ie.readystate = READYSTATE_COMPLETE: DoEvents: Loop
    
    ie.document.forms(4)("stockcode").Value = "13"
    ie.document.forms(4).submit
    
    Do While ie.busy Or Not ie.readystate = READYSTATE_COMPLETE: DoEvents: Loop
    
    'ie.Quit
    'Set ie = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top