Vba Internet Explorer 11自动化错误
使用excel中的vba在多个页面上导航时遇到问题。我在ie8和ie9上使用的代码没有任何问题,但在ie11中,当我导航到另一个url时,ie.locationurl和ie.document仍然引用以前的url。我注意到这只发生在php网站上。我有兴趣找到解决这个问题的方法。谢谢你的帮助 下面是php网站的一些示例代码:Vba Internet Explorer 11自动化错误,vba,Vba,使用excel中的vba在多个页面上导航时遇到问题。我在ie8和ie9上使用的代码没有任何问题,但在ie11中,当我导航到另一个url时,ie.locationurl和ie.document仍然引用以前的url。我注意到这只发生在php网站上。我有兴趣找到解决这个问题的方法。谢谢你的帮助 下面是php网站的一些示例代码: 子测试() Dim ie作为SHDocVw.InternetExplorer 设置ie=New SHDocVw.InternetExplorer 与ie .导航“https:/
子测试()
Dim ie作为SHDocVw.InternetExplorer
设置ie=New SHDocVw.InternetExplorer
与ie
.导航“https://www.facebook.com/“'php网站
.Visible=True
忙着干吧
环
请稍等,即readyState 4
环
.导航“https://en.wikipedia.org/wiki/Main_Page"
.Visible=True
调试.打印ie.locationurl
忙着干吧
环
请稍等,即readyState 4
环
以
端接头
这里有一个可以工作但没有php网站的网站:
子测试2()
Dim ie作为SHDocVw.InternetExplorer
设置ie=New SHDocVw.InternetExplorer
与ie
.导航“http://www.break.com/“'非php网站
.Visible=True
忙着干吧
环
请稍等,即readyState 4
环
.导航“https://en.wikipedia.org/wiki/Main_Page"
.Visible=True
调试.打印ie.locationurl
忙着干吧
环
请稍等,即readyState 4
环
以
端接头
在允许加载页面之前,您正在请求
Sub test()
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.navigate "https://www.facebook.com/" 'php website
Debug.Print "1." & .locationurl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Debug.Print "2." & ie.locationurl
.navigate "https://en.wikipedia.org/wiki/Main_Page"
Debug.Print "3." & .locationurl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Debug.Print "4." & .locationurl
End With
End Sub
我已将ie.Busy
和ie.readyState
检查配对,并将DoEvents
抛出到循环中,以允许在页面加载时进行一些处理。您没有充分利用块中的父ie
对象引用,因此我在块中截断了一些不必要的ie
引用
由于Internet Explorer版本与此问题相关,因此这是运行代码的版本
谢谢您的回答。您是否在internet explorer 11上运行了此操作,因为我刚刚运行了,但它仍然显示相同的错误:(进程在ie保持忙碌的最后一个循环中停止。是的,它是IE11版本11.0.960.18015,更新版本11.0.23(见上文).好的。我不知道问题出在哪里,因为这也发生在其他有ie11的工作计算机上。我有最新的更新11.0.10240.16431。我注意到如果我用F8运行代码,它会工作。忘了提到更新版本是11.0.22(KB3078071)
Sub test2()
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.navigate "http://www.break.com/" 'non php website
.Visible = True
Do While ie.Busy
Loop
Do While ie.readyState <> 4
Loop
.navigate "https://en.wikipedia.org/wiki/Main_Page"
.Visible = True
Debug.Print ie.locationurl
Do While ie.Busy
Loop
Do While ie.readyState <> 4
Loop
End With
End Sub
Sub test()
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.navigate "https://www.facebook.com/" 'php website
Debug.Print "1." & .locationurl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Debug.Print "2." & ie.locationurl
.navigate "https://en.wikipedia.org/wiki/Main_Page"
Debug.Print "3." & .locationurl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Debug.Print "4." & .locationurl
End With
End Sub
test
1.
2.https://www.facebook.com/
3.https://www.facebook.com/
4.https://en.wikipedia.org/wiki/Main_Page