VBA that will start internal timer during wait time for ie to reach ready state 4 RRS feed

  • Question

  • So basically, I have a macro that runs just fine and loops just fine. Occasionally though, the webpage experience an error that causes it to never load. IE just spins and spins, thus leading to an error. I am wondering, if within the IE reaching ready state 4 code, you could start an internal timer that basically just waits a max of  like 5 minutes, and if IE hasn't reached ready state 4 its just closes all instances of IE and then exits sub.

    Anything like that sound doable? Is an internal timer a thing?

    Thursday, October 6, 2016 8:51 PM

All replies

  • You need to look at Application.Ontime  .  If the page loads successfully you'll need to cancel the timer.  I use this a lot to poll for certain events. 

    I've had a lot of problems with IE 11.  I would recommend using Selenium Basic rather than Microsoft Internet Controls.  It comes with a lot of Excel examples.  It supports selecting elements with Xpath which is extremely powerful.  It supports Firefox, Chrome, IE and Edge.  I just finished a project with it and was really impressed.  The latest release is

    Firefox works with 46.0.1.  It hasn't been update to work with the latest version. 

    Selenium is used to test websites and is used by almost everyone.  You can use it with C#, Java, Ruby and other languages.  Someone developed Selenium Basic which supports VB.NET and VBA.

    Friday, October 7, 2016 1:21 PM
  • Adapt something like the following

    Dim timeOut As Single
        timeOut = Timer + 10    ' 10 seconds
        Do While Timer < timeOut ' Or ie.Busy Or ie.ReadyState <> 4
    ' loop code?   
    The 10 seconds is just to test the timeout. Change to suit and include any conditions that if true should end the loop

    Friday, October 7, 2016 3:14 PM