Visual Basic SHDocVw.InternetExplorer IsBusy is always true, object not updating

Short version:
I have a SHDocVw.InternetExplorer object that after Navigate is called does not finish loading. This browser control IsBusy = true, and ReadyState=1 despite the page in Internet Explorer can be visually seen as having finished loading. I've tried calling oIE.Refresh, but Visual Basic throws an exception (HRESULT E_FAIL has been returned from a call to a COM component). How can I get the object to show the updated webpage?

Long version:
I have a project that invokes a dynamic internet explorer object (the project does not allow having an in-application WebBrowser control). This is called by Dim oIE As SHDocVw.InternetExplorer.

There are 2 calls to oIE.Navigate. The first one works perfectly. On calling the second page the page does not load as previously described. Checking the oIE object in Debug mode shows that after calling the second Navigate, the oIE.URL is still set to the first pages URL, not the second.

If the following code is added (below) (after 2nd navigate) an infinite loop results.
Do While oIE.busy Or oIE.ReadyState <> 4

Here is the interesting part. If in debug mode, an execution breakpoint is placed immediately before the 2nd navigate command, run the program, and natually execution pauses. If the program is resumed doing with no other changes, the 2nd navigate works correctly.

Naturally that suggests giving the program a timeout. However using timers to pause execution, as well as using Sleep(), but neither works. Tried multiple calls to DoEvents (with more timeouts) before 2nd Navigate but that doesn't work either.

Is there a solution to making the second Navigate load the page correctly?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the command ..
.. is not the correct syntax

try ..
.. instead

This sample gives the webbrowser 10 seconds to load (or Refresh) the page:
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Private Sub Command1_Click()
    Call refreshIE(10, "")
    MsgBox oIE.Document.body.InnerHTML
End Sub

Sub refreshIE(ByVal Seconds2Wait As Long, ByVal L As String)
Static time0
time0 = timeGetTime
    If oIE.ReadyState > 2 Then 'ReadyState must be 3 or 4
        'oIE.Refresh: Exit Do
         oIE.Navigate L: Exit Do
    End If
    If (timeGetTime - time0) / 1000 >= Seconds2Wait Then Exit Do
VBA.Interaction.DoEvents ' or use just DoEvents
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tolvorAuthor Commented:
VBA.Interaction.DoEvents, as well as DoEvents are not valid subs in my VB2013.
I've reducted the code for another ajax site that exhibits the same problem. The main site that I want to test requires a login that making setting up test code difficult.

Execution on this code never finishes, and gets caught in an infinite loop.

Any help would be appreciated.


   Dim oIE As SHDocVw.InternetExplorer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        oIE = CreateObject("InternetExplorer.Application")
        oIE.Visible = True
        oIE.Navigate("")   '   

        Do While oIE.Busy Or oIE.ReadyState <> 4

        'Do While oIE.Busy Or oIE.ReadyState <> 4
        Label1.Text = "successful"
    End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.