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

Posted on 2014-09-02
Last Modified: 2014-09-10
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?
Question by:tolvor
    LVL 17

    Accepted Solution

    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


    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now