问题描述
我正在使用带有VBA的旧Excel文档,它可以在Windows 7上与IE 11一起使用,但是在Windows 10上的IE 11上它不起作用。 IE 11启动到所请求的URL,但就是这样。无论何时我尝试访问事件,方法或属性,它都会停止。没有错误代码,没有崩溃,只是停止。
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.
我已经确认我对 Microsoft Internet Controls 和 Microsoft HTML对象的引用包含库(它们不是,但它们现在是)。
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
检查代码从未执行,我之前放置了MsgBox代码然后进行测试。在循环之前只有MsgBox工作,除非我尝试使用 MsgBox ie.Document.Title
,但我可以做 MsgBox ie.ReadyState
或 MsgBox正在加载网页
就好了。
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.
再次代码完全没问题在Windows上没问题7使用IE 11,但在使用IE 11的Windows 10上不起作用。在多台具有相同结果的W7和W10机器上测试。
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.
推荐答案
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.
- 启动 IE 11
- 点击工具
- 点击兼容性视图设置
- 在文本区域输入您的网址,然后点击添加
- 选中以兼容模式显示Intranet网站
- 点击关闭
- Launch IE 11
- Click Tools
- Click Compatibility View Settings
- Type your URL into the text area and click Add
- Check Display Intranet sites in Compatibility Mode
- Click Close
执行此操作后,我退出IE 11,重启我的Excel电子表格与之前无法运行的VBA。执行VBA代码,它就像在Windows 7上使用IE 11一样。
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.
特别感谢 OmegaStripes 与我一起坚持并帮助我看到实际问题,而不是过度思考。
Special thanks to OmegaStripes for sticking through this with me and helping me see the actual problem rather than over thinking it.
这篇关于VBA InternetExplorer.Application对象挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!