mikit
mikit

Reputation: 21

Excel VBA - Win10, IE11 - opening second webpage is not working

we've migrated to win10 and IE11and some of my vba macros stopped working. I could resolve some, but I am having issues with resolving following problem.

I have a macro, that opens a webpage in IE. This webpage is opened just to log in to the database. There is a list of customers. Each customer has specific ID which is reflected also in URL. Instead of searching through html code, I am simply entering this customer specific URL to IE. Problem is, that this stopped working on Win 10 IE11. First page (the one used to log in) is opened, but then second URL is not entered and macro gets stucked while it is waiting till that second, customer specific page is loaded. There is also third page which I need to access and its URL is the same for each customer, that's why I need to access log in page first, then customer specific page and then the third page where the list of devices for that customer is. Going directly to device list page is not working. Also, I am not getting any errors or anything like that.

Here is my code:

        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")

        ie.Visible = True
        ie.Document.Focus

        ie.Navigate "https://webpage_used_to_log_in.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents
        Wend

        ie.Navigate = "https://customer_specific_webpage.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents                         'the macro stucks here as customer page is never entered and opened
        Wend

        ie.Navigate = "https://device_list.com"
        While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
            DoEvents  
        Wend                       

This was perfectly working in Win7 and IE11. I couldn't find any solution to this issue. If you have any idea how this could be fixed, I'd really appreciate your help. Thank you.

Upvotes: 1

Views: 1071

Answers (3)

mikit
mikit

Reputation: 21

Here is what is working for me:

    Dim ie As Object
    Set ie = New InternetExplorerMedium  'used this to fix the issue with reading data from html code

    ie.Visible = True
    ie.Document.Focus

    ie.Navigate "https://webpage_used_to_log_in.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    ie.Navigate = "https://customer_specific_webpage.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    ie.Navigate = "https://device_list.com"
    Do Until.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop   

Thank you all for your help.

Upvotes: 1

Zwenn
Zwenn

Reputation: 2267

this can't work:

While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
  DoEvents
Wend

You set the opposite conditions, that the browser has to be Busy or the ReadyState has to be set to Complete for the loop to continue. So it's an endless loop.

This is how it works:

Sub LOADIE()
  Dim ie As Object
  Set ie = CreateObject("InternetExplorer.Application")
  ie.Visible = True

  ie.Navigate "https://www.google.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop

  ie.Navigate "https://www.stackoverflow.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop

  ie.Navigate "https://www.bing.com"
  Do Until ie.ReadyState = 4: DoEvents: Loop
End Sub

All you have to do is check busy or ReadyState. I also wonder why the login page has to be called if there is no login at all.

Best regards

Zwenn

Upvotes: 0

Yu Zhou
Yu Zhou

Reputation: 12999

Maybe the equal-signs = in the second and third ie.Navigate cause the issue. I think that's a wrong expression. The below code can work well in my IE11 in win10, you could have a try:

Sub LOADIE()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True

    ie.Navigate "https://www.google.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend

    ie.Navigate "https://www.stackoverflow.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend

    ie.Navigate "https://www.bing.com"
    While ie.Busy Or ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Wend
End Sub

Upvotes: 0

Related Questions