【发布时间】:2016-04-01 18:46:02
【问题描述】:
我有一些代码可以通过 VBA 中的 Internet Explorer 自动化从多个网站检索数据。我的代码在 IE8 上运行没有问题,但在 IE11 中,调用 Internet Explorer 对象的 Navigate 方法后,Document 和 LocationURL 没有更新;他们仍然引用之前显示的网站。下面是一些重现问题的代码:
Sub Test()
Debug.Print "start"
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://en.wikipedia.org/wiki/Visual_Basic"
wait ie
Debug.Print "Current URL: " & ie.LocationURL
ie.Navigate "http://en.wikipedia.org/wiki/Microsoft_Office"
wait ie
Debug.Print "Current URL: " & ie.LocationURL
Set ie = Nothing
End Sub
Sub Wait(ie As Variant)
Do While ie.Busy
Application.wait DateAdd("s", 1, Now)
Loop
End Sub
在装有 IE8 的机器上运行上述 Test 子程序时,它会打印两个不同的 URL,这是预期的行为。但是,当我在使用 IE11 的机器上运行相同的代码时,它会打印第一个 URL 两次。知道可能出了什么问题吗?
更新:我找不到解决方案,所以我寻求为每个 URL 打开一个新的 IE 窗口的解决方法。
【问题讨论】:
标签: vba internet-explorer