VBA InternetExplorer.Application 对象挂起 [英] VBA InternetExplorer.Application Object Hang

查看:15
本文介绍了VBA InternetExplorer.Application 对象挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 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 ControlsMicrosoft 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.ReadyStateMsgBox "Loading pages"就好了.

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.

同样,该代码在带有 IE 11 的 Windows 7 上运行良好,没有问题,但在带有 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.

推荐答案

在尝试了许多不同的选项后,我终于能够让它工作了.根据 OmegaStripes 的建议,我开始搞乱兼容模式.像许多事情一样,最简单的解决方案最终成为正确的解决方案.将我的 Intranet 站点添加到兼容性视图设置后,它可以完美地对 VBA 进行零代码更改.

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. 启动 IE 11
  2. 点击工具
  3. 点击兼容性视图设置
  4. 在文本区域中输入您的网址,然后点击添加
  5. 检查在兼容模式下显示 Intranet 站点
  6. 点击关闭

完成此操作后,我退出了 IE 11,使用以前无法运行的 VBA 重新启动了我的 Excel 电子表格.执行了 VBA 代码,它的工作方式与使用 IE 11 的 Windows 7 一样.

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 对象挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆