?
Solved

Internet Explorer ActiveX Control - .busy property doesn't work in do loop.

Posted on 2003-02-25
18
Medium Priority
?
1,499 Views
Last Modified: 2013-11-26
This problem won't go away.

I'm using a Microsoft Web Browser control embedded into a Excel VBA Userform. I'm writing a script which will automate form entry on an intranet site and proceed through each page.

The lines of code I keep finding when looking for ways to 'wait' for the page to load are as follows.

Do Until webbrowser1.ReadyState = READYSTATE_COMPLETE
 DoEvents
Loop

and

Do until webbrowser1.busy = false
 DoEvents
Loop

Neither of these work. With the first example, the script hangs. It seems that the do loop, despite the do events, doesn't give the control enough 'breathing space' to actually load the page. In the second example, .busy seems to return false even while nested frames are still loading. The next line in the program then fires, (referencing a form variable which isn't there yet) causing it to drop an error message. Even once I've figured this out I need to get some detection for timeouts.

Has anyone else had any problems, specifically when using Excel VBA or does anyone know what I might try next?

Many thanks,

Beale
0
Comment
Question by:TheRealBeale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
  • +4
18 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8018063
Do until webbrowser1.busy = true
 DoEvents
Loop
0
 

Author Comment

by:TheRealBeale
ID: 8018119
That doesn't solve my problem really. I'm trying to wait until .busy = false. We assume it's true to begin with and that it will eventually become false. As I said before the whole

Do until webbrowser1.busy = false
DoEvents
Loop

concept doesn't seem to work...

Or am i missing something..

B
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8018196
correct, it is true while you are loading the page, so when it is done loading it exits the loop and .busy = false.

i don't see what the problem is?

if you are trying to wait until .busy = false, then it will be after the loop.

maybe i'm missing something.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:TheRealBeale
ID: 8018299
Tried your code. Still no joy.

Translated into English, my line of code just means 'until the browser stops being busy, do stuff.' Then it should move on.

I just get a 'Object doesn't support this property or method' message at the next line of code which is

UserForm1.WebBrowser1.Document.frames.topFrame.form1.Search.Value = "fhm"

which errors out becuase it can't reference the object because the page hasn't loaded yet. This line works fine once the page has loaded. My problem is getting it to load the page and all nested frames and only then move onto the next line.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8018381
so this doesn't work?

Do while webbrowser1.busy = true
   DoEvents
Loop

'' the page is loaded now so this should work
UserForm1.WebBrowser1.Document.frames.topFrame.form1.Search.Value = "fhm"

0
 
LVL 5

Expert Comment

by:bob_online
ID: 8018452
Can you trap the error and return to the line  

UserForm1.WebBrowser1.Document.frames.topFrame.form1.Search.Value = "fhm"

when the error code is "object doesn't...etc"

In effect, this gives you a "loop" that will loop until the form is loaded.  You could put a counter in there so that it cleanly exits after what you consider to be a reasonable period of time.  Increment it by 1 each time you hit the error and when it gets to 100 or 1000 or whatever, stop trying.
 
 
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8018635
If i understood: you cannot access the Document object until the page is fully downloadaded, so, if you need to access it use DocumentComplete event of webbrowser1

if (pDisp is webbrowser1.object) then
    WebBrowser1.Document.frames.topFrame.form1.Search.Value = "fhm"

end if
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8018667
One more thing:
If you need to wait for some reason, don't trust in .Busy property.
Try to set a boolean global variable:
dim bolComplete as boolean

In DocumentComplete event of webbrowser1

if (pDisp is webbrowser1.object) then
   bolComplete=true
end if

and in your loop
do
   'doevents
loop until bolComplete = True
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 8019149
Busy property has always been "flaky" in its functionality.  I usually try and keep it limited to utilizing the DocumentComplete event as stated, or, more reliable than Busy is:


Browser.Navigate "..."
DoEvents

Do Until Browser.ReadyState = READYSTATE_COMPLETE
    DoEvents
Loop
0
 

Author Comment

by:TheRealBeale
ID: 8244756
Thanks for your help on this, but none of these have worked. Even Microsoft's own documentation states these as possible ways of doing it but still none of them work.

I'm using a standard webbrowser object in Excel 97 VBA, if that's any help. It looks like the whole browser object would be happier if it had it's own thread, but not possible without VBA 6. Seems that the DoEvents doesn't allow the browser any room to process the query. Has anyone else had these kinds of problems with VBA or have any of you got some Excel VBA code known to work.

Many thanks..

Beale
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8245406
As i alreday told you, don't trust in .busy property of the control.
If you need to wait until page is fully downloaded (busy=False), use DocumentComplete event, believe me, it works.!

You could open your own internet explorer instance if you want.
Set a reference to microsoft internet controls

in general declarations sections of your form:
Dim WithEvents IE As SHDocVw.InternetExplorer

you could use its properties and methods like you did with the webbrowser control.

That doesn't means that you will solve .busy matter with this.
0
 

Author Comment

by:TheRealBeale
ID: 8253293
I've stopped using the .busy property as you recommended. My new code uses the DocumentComplete handler.

To test this handler, I told it to fill a label with the word 'Done' when it had finished navigating to a page. So THAT bit works.

Set up a global boolean variable called bolPageLoaded which is set to false to begin with and then is set to true by this handler.

Then there's a

Do Until PageLoaded = True
    DoEvents
Loop

in the main code after the .navigate() method has been called. It's at this point that the problems start, as the page does not submit the form and move on and just hangs there. If you do it manually it's fine.

Would calling an IE instance be more reliable or would I end up in the same pickle?

Cheers

Beale
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8253464
same pickle.

But maybe you are doing something wrong. How do you populate the form and submit it? Maybe there is the problem.
Regarding populate the form and submit take a look at ..
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 1200 total points
ID: 8253472
0
 

Expert Comment

by:CleanupPing
ID: 8901129
TheRealBeale:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 8902227
Recommendation: Points to Richie_Simonetti
0
 

Author Comment

by:TheRealBeale
ID: 8927472
Richie - looks like you'll get the points. Project has been delayed a bit and I'm going to try out your thinking tonight and then post something back.

Believe I may have tried using this technique before to no avail.

Regards
Beale
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8972814
Moderator, my recommended disposition is:

    Accept Richie_Simonetti's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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