• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

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?
1 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, "http://sample.com")
    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

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("http://www.happybidday.com/index.php")   ' https://us.etrade.com/home   

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

        'Do While oIE.Busy Or oIE.ReadyState <> 4
        Label1.Text = "successful"
    End Sub

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now