VBA Excel 在一个 IE 中打开多个网站 window
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
在这个事件中,第二个link被打开,第一个被完全省略。
最重要的是,我想在同一个 window(作为不同的选项卡)中打开它们。
我在这里找到了一些解决方案:
Excel VBA control IE
看起来需要某些功能。
有人能帮忙吗?
我建议您将两个 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)
它将修复您的语法错误,并且 url 将在 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 代码切换选项卡以在特定页面上执行代码。
我已经成功地使用 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
在这个事件中,第二个link被打开,第一个被完全省略。 最重要的是,我想在同一个 window(作为不同的选项卡)中打开它们。
我在这里找到了一些解决方案:
Excel VBA control IE
看起来需要某些功能。 有人能帮忙吗?
我建议您将两个 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)
它将修复您的语法错误,并且 url 将在 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 代码切换选项卡以在特定页面上执行代码。