Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 views
in Technique[技术] by (71.8m points)

excel - VBA InternetExplorer.Application Object Hang

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...