Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Wait on IE to finish before moving on


Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-2012, 05:40 PM
brittonsm brittonsm is offline
Newcomer
 
Join Date: Jul 2012
Posts: 2
Default Wait on IE to finish before moving on


After if fire this event Excel doesn't always wait long enough for the event to complete - I put in a dumb loop to "usually" works, but I know there's a correct way to do this. Any ideas?

ie.document.getElementById("ctl00_ctl00_cphMain_cphMain_ddlReceiveBran ch").fireevent ("onchange")

'WHAT I'M USING
For dumb = 0 To 100000
DoEvents
Next

'THESE DON'T WORK...
Do While ie.busy
DoEvents
Loop

Do While ie.ReadyState <> 4
DoEvents
Loop
Reply With Quote
  #2  
Old 07-15-2012, 07:52 AM
mjclare mjclare is offline
Freshman
 
Join Date: Nov 2007
Posts: 29
Default

Here is the 'wait function that I use to force my code to wait for ie to finish. You can see it demonstrated in a code snippet here: http://www.xtremevbtalk.com/showthre...ighlight=lwait

Note that if the site that you are scraping uses frames, the object that you send to this is not just the LOIE object; you have to send it the specific frame object that is being refreshed.

Mike Clare

Code:
Function lWait(LOIE As Object) As Boolean
  Dim t1 As Long
  Dim t2 As Long
  On Error Resume Next
  t1 = Timer
  t2 = t1 + 60
  Do
    If Timer > t2 Then lWait = False: Exit Function
    If VarType(LOIE.document) = vbString Then Exit Do
  Loop
  Do
    If Timer > t2 Then lWait = False: Exit Function
    If LOIE.busy = False Then Exit Do
  Loop
  Do
    If Timer > t2 Then lWait = False: Exit Function
    If VarType(LOIE.document.readystate) = "C" Then Exit Do
  Loop
  Do
    If Timer > t2 Then lWait = False: Exit Function
    If LOIE.document.readystate = "complete" Then Exit Do
  Loop
  lWait = True
End Function
Reply With Quote
  #3  
Old 07-30-2012, 09:10 AM
angle2k3 angle2k3 is offline
Freshman
 
Join Date: Mar 2010
Posts: 37
Thumbs up

its been a while since i've done anything like this, but i'm fairly certain the only really robust way to do this was to reload the document object and
poll for a string (in the html or url) you were expecting on the new page

along the lines of
Code:
 
set doc = IE.document
while (instr(doc.innerHtml, "your_search_string") = 0)
'or try searching doc.LocationURL 
   'wait 1 second before polling again
   application.wait(now() + timeserial(0,0,1))  
wend
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->