Var*_*ryl 15 excel internet-explorer vba excel-vba
所以,我使用Excel VBA代码点击我们网站上的按钮,相信我,我知道这不是最好的事情,但它是目前我可用的最不令人反感的选择.
所以,这个选择的方式,这里是我的问题,我可以使用这个代码,成功加载imdb.com,谷歌等.但是,当我加载我们的本地网站,我失去对ie对象的控制,我不能检查readyState,我不能退出.这是我得到的错误.运行时错误'-2147023179(800706b5)':
自动化错误接口未知
每隔一段时间我就会收到此消息:运行时错误'-2147417848(80010108)':
自动化错误调用的对象已与其客户端断开连接.
单击Debug指示ie.readyState,我也尝试将其注释掉,然后指向ie.Quit
Sub dothestuff()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www.google.com/"
anerror = webload(ie)
ie.Quit
Set ie = Nothing
End Sub
Function webload(ie)
Do Until ie.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
End Function
Run Code Online (Sandbox Code Playgroud)
小智 28
以下是此问题的快速简便解决方案:
代替:
set IE = createobject("internetexplorer.application")
Run Code Online (Sandbox Code Playgroud)
使用:
Set IE = New InternetExplorerMedium
Run Code Online (Sandbox Code Playgroud)
无需调整IE设置
Jim*_*m M 17
这是正在发生的事情.当您的浏览器在内部"跳转"到不同的安全区域时 - 从本地地址到inTRAnet地址或到internet地址 - IE关闭/删除IE的当前进程并打开另一个具有更严格安全性的进程.旧的和新的IE进程是IE子任务的IE子进程,因此您不会通过观察浏览器或在任务管理器中查看进程来看到它.如果您使用Process Explorer(从Microsoft免费),您可以看到这种情况发生.
您需要在此类环境中使用Anup Upadhyay的解决方案.他的代码片段查看了所有IE任务(父和子没有区别),并找到指向原始进程的Web地址的新IE进程.只要您没有多个浏览器打开到同一个地址,它就会可靠地找到新进程并继续进行,就像您期望的那样.
注意:您可能还需要使用InternetExplorerMedium对象而不是InternetExplorer对象.在"坚持"会议方面也更好.
这是我的版本,与Anup的版本差不多.
MS Office VBA的参考:
Microsoft Internet Controls
Microsoft Shell控件和自动化
ñ
Dim IE As InternetExplorerMedium ' This object (the "medium" variety as opposed to "InternetExplorer") is necessary in our security climate
Dim targetURL As String
Dim webContent As String
Dim sh
Dim eachIE
targetURL = "[your URL here]"
Set IE = New InternetExplorerMedium
IE.Visible = False ' Set to true to watch what's happening
IE.Navigate targetURL
While IE.Busy
DoEvents
Wend
Do
Set sh = New Shell32.Shell
For Each eachIE In sh.Windows
If InStr(1, eachIE.LocationURL, targetURL) Then
Set IE = eachIE
'IE.Visible = False 'This is here because in some environments, the new process defaults to Visible.
Exit Do
End If
Next eachIE
Loop
Set eachIE = Nothing
Set sh = Nothing
While IE.Busy ' The new process may still be busy even after you find it
DoEvents
Wend
Run Code Online (Sandbox Code Playgroud)
我们使用IE9遇到了这个问题.它出现是因为安全设置."Internet选项"对话框的"安全"选项卡上有一个名为"启用保护模式"的设置(工具...互联网选项).每个"区域"可以具有"启用保护模式"的不同设置我们取消选中"启用保护模式",这解决了我们的问题.我认为发生的事情是当切换到处于保护模式的区域时,IE启动一个新进程来处理该区域中的流量(可能会杀死旧进程).发生这种情况时,VBA中的IE对象变量将从Internet Explorer断开连接.
小智 7
试试这个:
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
Run Code Online (Sandbox Code Playgroud)