[英]VBA Excel open multitude websites in the one IE window
我设法使用 VBA Excel 打开 Internet Explorer。
我的代码如下所示:
Sub IE()
Dim ie As object
Dim location
'Dim button
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate ("https://fulcrum/NewBuild/Record.aspx?ID=" & Range("B1").Value)
.Navigate ("http://gcommswebmapgb/portal/")
.Top = 5
.Left = 5
.Height = 1300
.Width = 1900
While ie.ReadyState <>4
Do Events
Wend
Set location = .document.getElementById("__VIEWSTATE")
'Set button = .document.getElementById("btnContainer").Children(0)
'button.Click
While ie.ReadyState <> 4
DoEvents
Wend
End With
Set ie = Nothing
End Sub
在这种情况下,第二个链接被打开,第一个完全省略。 最重要的是,我想在同一个窗口中打开它们(作为不同的选项卡)。
我在这里找到了一些解决方案:
看起来需要一些功能的地方。 有人可以帮忙吗?
我建议您将两个 URL 存储在如下变量中。
Dim url1, url2 As String
url1 = "https://fulcrum/NewBuild/Record.aspx?ID=" & Range("B1").Value
url2 = "http://gcommswebmapgb/portal/"
然后尝试将 URL 变量传递给.Navigate没有圆括号,如下所示。
With ie
.Visible = True
.Navigate url1
.Navigate url2, CLng(2048)
它将修复您的语法错误,网址将在 2 个选项卡中打开。
修改后的代码:
Sub ie()
Dim ie As Object
Dim location
'Dim button
Dim url1, url2 As String
url1 = "https://fulcrum/NewBuild/Record.aspx?ID=" & Range("B1").Value
url2 = "http://gcommswebmapgb/portal/"
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate url1
.Navigate url2, CLng(2048)
' .Top = 5
' .Left = 5
' .Height = 1300
' .Width = 1900
While ie.ReadyState <> 4
'Do Events
Wend
'Set location = .document.getElementById("__VIEWSTATE")
'Set button = .document.getElementById("btnContainer").Children(0)
'button.Click
While ie.ReadyState <> 4
DoEvents
Wend
End With
Set ie = Nothing
End Sub
输出:
此外,您需要检查您的代码是否正确引用了正确的选项卡以执行更多代码。 请注意,您不能同时自动化两个页面。 您需要使用 VBA 代码切换选项卡以在特定页面上执行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.