I have managed with opening the Internet Explorer using VBA Excel.
My code looks as follows:
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
In this event, the 2nd link is opened and 1st one completely omitted. On top of that, I would like to open them in the same window (as a different tab).
I found some solutions here:
VBA Excel input data into already opened ie window
where it looks that some functions are required. Is anyone able to help?
I suggest you store both URLs in a variables like below.
Dim url1, url2 As String
url1 = "https://fulcrum/NewBuild/Record.aspx?ID=" & Range("B1").Value
url2 = "http://gcommswebmapgb/portal/"
Then try to pass the URL variables to .Navigate without round brackets like below.
With ie
.Visible = True
.Navigate url1
.Navigate url2, CLng(2048)
It will fix your syntax error and urls will be opened in 2 tabs.
Modified code:
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
Output:
Further, you need to check that your code properly references the correct tab to execute further code. Note that you cannot automate both pages at the same time. You need to switch the tabs using your VBA code to execute code on specific page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.