Vba 获取InternetExplorer对象的ReadyState时发生自动错误
我在同一行上有两个不同的错误。有时这一个: 自动化错误:调用的对象已与其客户端断开连接 有时: 接口未知 再现错误的最小代码:Vba 获取InternetExplorer对象的ReadyState时发生自动错误,vba,internet-explorer,excel,Vba,Internet Explorer,Excel,我在同一行上有两个不同的错误。有时这一个: 自动化错误:调用的对象已与其客户端断开连接 有时: 接口未知 再现错误的最小代码: Sub mcve() Dim ie As Object Dim www As String Set ie = New InternetExplorerMedium www = "http://www.stackoverflow.com" ie.navigate www ie.Visible = False Whil
Sub mcve()
Dim ie As Object
Dim www As String
Set ie = New InternetExplorerMedium
www = "http://www.stackoverflow.com"
ie.navigate www
ie.Visible = False
While ie.ReadyState <> 4 ' <~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs here
DoEvents
Wend
End Sub
Sub-mcve()
模糊的物体
将www变暗为字符串
设置ie=新的InternetExplorerMedium
www=”http://www.stackoverflow.com"
浏览
可见=假
而ie.ReadyState 4'引用…>Microsoft Internet控件
当ie.ReadyState 4第二次出现时,该错误发生在。如何修复此问题?而不是
Set ie = New InternetExplorerMedium
只用
Set ie = New InternetExplorer
或者,对于后期绑定:
Set ie = CreateObject("InternetExplorer.Application")
这使错误消失
我不知道你为什么要首先使用InternetExplorerMedium
。引用以下小字:
备注
Windows Internet Explorer 8。在Windows Vista上,要创建以中等完整性级别运行的Internet Explorer实例,请将CLSID\u InternetExplorerMedia
(在exdisp.idl中定义)传递到CoCreateInstance
。生成的InternetExplorerMedium
对象支持与InternetExplorer
对象相同的事件、方法和属性
你真的在WindowsVista上使用IE8吗?你真的想要“中等完整性级别”吗?我不这么认为。这是一个复制品。问题似乎是由Internet Explorer安全设置引起的-在安全区域之间切换时,IE的当前实例将被终止,并创建一个新实例,因此您对旧进程的引用不再有效
建议的一些解决办法是:
更改IE安全设置。在Internet选项的安全选项卡上取消选中“启用受保护模式”
直接导航到IP地址而不是URL。这是给我修的。例如,ie.navigate“64.233.177.106”
(谷歌的IP地址)
Set ie=New InternetExplorerMedium
而不是New InternetExplorer
。或者在你的情况下,反之亦然
打开Internet Explorer,然后转到Internet设置,打开“站点”并清除需要服务器压缩的网页。问题在于服务器压缩