Visual Basic, cannot Refresh an IE object (SHDocVw.InternetExplorer), throws exception

I have an application that first navigates to a website by invoking a separate IE browser window via calls to SHDocVw.InternetExplorer (project requirement is that the browser cannot be in the app). When oIE.Navigate is called the IE browser correctly goes to the requested page. A loop is called to check whether the page is fully loaded (certain HTML text) and if after 10 seconds it will try to refresh the page. However calls to oIE.Refresh generate an exception (Error HRESULT E_FAIL has been returned from a call to a COM component. StackTrace: at SHDocVw.IWebBrowser2.Refresh()  )  I have already implemented a loop to recheck the page's html code every 1/2 sec to wait for the page to update, but it continues to show the old page info.

The puzzling part of this is when I look at the browser window myself I do see that the page has fully loaded and the key phrase is in fact on the page, but oIE.Document.body.InnerHTML does not contain the phrase, just a old version of the page before the HTML was updated by javascript.

 Is there a way to tell the SHDocVw.InternetExplorer to get the new HTML from the IE browser window, or at least call Refresh?

Thanks
tolvorAsked:
Who is Participating?
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.

vb_elmarCommented:
Before refreshing the browser we have to use 'DoEvents' to give the browser enough time. If we do not use DoEvents oIE.Refresh generates the exception Error.

The oIe.ReadyState must be minimum 3. When the ReadyState is 3 or 4 the page is fully loaded and we can call the newest oIE.Document.body.InnerHTML

Do
DoEvents
If oIe.ReadyState > 2 Then oIe.Refresh: Exit Do
Loop

Open in new window

0

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:
Excellent. Many thanks
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.