0

Trying to run some simple code, just to open a website up. However keep getting Automation Error: The object invoked has disconnected from its clients. Code below. Code debugger jumps to highlighting Do While oIE.ReadyState <> 4


Sub test()

    Set oIE = CreateObject("InternetExplorer.application")
    oIE.Visible = True

    oIE.navigate ("https://www.google.com")
    Do While oIE.ReadyState = 4: Application.Wait (Now + TimeValue("0:00:01")): Loop
    Do While oIE.ReadyState <> 4: Application.Wait (Now + TimeValue("0:00:01")): Loop

    ' example ref to DOM
    MsgBox oIE.Document.GetElementsByTagName("div").Length

End Sub


  • Try declaring and assigning the object like this: `Dim ie As InternetExplorer` and `Set ie = New InternetExplorerMedium` – riskypenguin Oct 22 '19 at 13:51
  • 1
    @M.Schalk That's not correct. That would change Late Binding into Early Binding! – Pᴇʜ Oct 22 '19 at 13:55
  • 3
    @Sam Your code works. I declared `Dim oIE As Object` tested it without getting any errors. The code is correct. The issue cannot be reproduced. – Pᴇʜ Oct 22 '19 at 13:57
  • @Pᴇʜ You're right, but how does that make it incorrect? If I work on a project by myself (i.e. no chance of compatability issues between computers) I prefer Early Binding, since it allows me to use IntelliSense. – riskypenguin Oct 22 '19 at 14:05
  • @M.Schalk Because it might not be what the OP intended and doesn't relate to the actual issue. Also your suggestion doesn't work without setting a reference. So you cannot say that Early Binding is better in general. In my eyes it doesn't make any sense to change something that is obviously not realated with the actual issue. Late Binding works perfectly so no reason to change it. – Pᴇʜ Oct 22 '19 at 14:13
  • 1
    Do you have IE installed on your computer? – Zac Oct 22 '19 at 14:54
  • Try `Set oIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")` – omegastripes Oct 22 '19 at 15:15
  • Check [this settings](https://stackoverflow.com/a/57094762/2165759) also. – omegastripes Oct 22 '19 at 16:58
  • Which version of Office version are you using? I have created [a sample](http://jsfiddle.net/7nyjoLat/1/) based on your code, the code works well on my machine(using Excel 2016).Besides, you could try to use the `While` statement, [like this](http://jsfiddle.net/k6qmpsf8/). And, you could also check these threads: [thread 1](https://stackoverflow.com/questions/42403210/internet-explorer-vba-automation-error-the-object-invoked-has-disconnected-from) and [thread 2](https://answers.microsoft.com/en-us/msoffice/forum/all/vba-code-problem-the-object-invoked-has/31ddc1e7-d335-44eb-aa08-abc681b8f833) – Zhi Lv Oct 23 '19 at 06:02

0 Answers0