2

I'm using an old Excel document with VBA that works fine with IE 11 on Windows 7, however on IE 11 on Windows 10 it does not work. IE 11 launches to the URL requested but that's it. Anytime I try to access a event, method, or property, it stops. No error code, no crash, just stops.

I've confirmed that my references to Microsoft Internet Controls and Microsoft HTML Object Library are included (they weren't but they are now).

Dim ie As Object

If ie Is Nothing Then
   Set ie = CreateObject("InternetExplorer.Application")
   ie.Visible = True
End If

url = "www.myurl.com"

ie.Navigate url

While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend

Code bellow the check never executes, I placed MsgBox code before and after for testing. Only MsgBox before the loop works, unless I try to use MsgBox ie.Document.Title, but I can do MsgBox ie.ReadyState or MsgBox "Loading webpage" just fine.

Again the code works perfectly fine no problem on Windows 7 with IE 11, but does not work on Windows 10 with IE 11. Tested on multiple W7 and W10 machines with identical results.

Iron3eagle
  • 1,077
  • 7
  • 23
  • 2
    When you open IE 11 manually in Windows 10 do you have any message boxes that automatically appear? e.g. "Make this your default browser" etc. – Jordan Jan 09 '17 at 17:02
  • 1
    By the loop do you mean `While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend`? It is normal, that trying to get `ie.Document.Title` before this loop won't work, as document hasn't fully loaded yet and getting its title will fail. How does it "stop"? Do you mean it's stuck in the loop? Try to step through code with F8. Check what ie.ReadyState value is. – Ryszard Jędraszyk Jan 09 '17 at 17:35
  • Try the loop `Do: Debug.Print TypeName(ie): DoEvents: Loop While ie.ReadyState <> 4 Or ie.Busy`, and show the output. – omegastripes Jan 09 '17 at 17:40
  • @RyszardJędraszyk That makes sense. Yes it appears to be stuck in the `ieReadyState` loop. I tried stepping through it by placing a break on the code but it doesn't allow me to step through it. – Iron3eagle Jan 09 '17 at 18:07
  • @Jordan No it does not. SInce I'm a new machine (having migrated from a Window 7 environment) I manually launched IE 11 to make sure. IE 11 launches to the web site fine, but the code under the ReadyState loop will not excute, even a simple MsgBox will not execute. – Iron3eagle Jan 09 '17 at 18:10
  • 1
    Try to hover over ie.readystate to see its value or use ctrl+G in VB editor, make this input: `?ie.readystate` and confirm with ENTER. In the end IE is not the most reliable thing. I once had to change the macro from `ie.ReadyState <> 4` to `ie.ReadyState <3`, the website did not fully load but it was enough for me to get data. The cause of problem were some of Google Ads not loading properly. – Ryszard Jędraszyk Jan 09 '17 at 18:19
  • @omegastripes tried your loop, `Debug.Print` returned Object when I broke on that line and IWebBrowser2 when I just let it run with out a break. – Iron3eagle Jan 09 '17 at 18:20
  • @RyszardJędraszyk I get a Run-time error '424': Object required. I modified @omegastripes test code to `Debug.Print ie.ReadyStatus` and it seems to continually report 0. – Iron3eagle Jan 09 '17 at 18:24
  • 3
    @defaultNINJA Object TypeName means that IE ActiveX object has disconnected, such issue are being detected for some websites which IE is not working stable on. Take a look at [this answer](http://stackoverflow.com/a/23232573/2165759). – omegastripes Jan 09 '17 at 18:31
  • Is it `ReadyState` or `ReadyStatus`? One of them is wrong. Also if you have a reference to the type library, you don't need to late-bind so you could declare your `ie` object variable `As InternetExplorer` (instead of `As Object`), and get IntelliSense upon typing the dot after `ie`. You only need late-binding when you're **not** referencing the type library. – Mathieu Guindon Jan 09 '17 at 18:35
  • @Mat'sMug It's `ReadyState` I fat fingered it in the comment. Thanks for the late binding tip. – Iron3eagle Jan 09 '17 at 18:41
  • @omegastripes Tried the options given in the different updates to the answer you had posted, but none of them worked. All ended with the same results. I feel like this is a permission issues or I'm still missing references. – Iron3eagle Jan 09 '17 at 21:18
  • 1
    @defaultNINJA could you please share the URL and what actions you want to do after the document loaded? – omegastripes Jan 09 '17 at 21:51
  • @omegastripes The URL is an internal site. Once accessed I get a text box by element id and then paste contents into it. I then get the submit button by element id and click it. I then get the results. I've added Debug.Print text inside the ready state loop to watch the loop, sometime it goes once, sometimes twice. However, once it either crashes or exits the next line of code is never executed, by it a Debug.Print or MsgBox. – Iron3eagle Jan 10 '17 at 17:11
  • 1
    Try to play with variations of IE [compatibility](https://www.google.ru/search?q=ie+compatibility+mode&tbm=isch), [browser](https://www.google.ru/search?q=ie+browser+mode&tbm=isch) and [document](https://www.google.ru/search?q=ie+document+mode&tbm=isch) modes. – omegastripes Jan 11 '17 at 03:40

1 Answers1

1

After trying many different options I was finally able to get it to work. Per OmegaStripes recommendation, I began messing with the compatibility modes. Like many things, the simplest solution ended up being the correct one. After adding my intranet site to the compatibility view settings it worked perfect with zero code changes to the VBA.

  1. Launch IE 11
  2. Click Tools
  3. Click Compatibility View Settings
  4. Type your URL into the text area and click Add
  5. Check Display Intranet sites in Compatibility Mode
  6. Click Close

After doing this I exited IE 11, restarted my Excel spread sheet with the VBA that was previously not functioning. Executed the VBA code, and it worked just as it did on Windows 7 with IE 11.

Hope this helps some one else and saves them a lot of headache.

Special thanks to OmegaStripes for sticking through this with me and helping me see the actual problem rather than over thinking it.

Iron3eagle
  • 1,077
  • 7
  • 23