Reputation: 21
I'm attempting to create a macro through VBA to open a specified set of links in multiple tabs on IE. Currently I'm using the code below, and it works most of the time if I am trying to open 3 or less tabs. Anything more than 3, the code crashes at the "Navigate2" section. After some research, I cannot seem to find a common issue or a resolution for this. The code appears similar to below (links have been removed for obvious reasons).
Any help would be greatly appreciated.
Sub USD_ILB()
Dim strURL As String
Dim file_date As String
Dim objIE As Object
Dim arrSites(4)
file_date = Format(Cells(1, 2), "dd.mm.yyyy")
arrSites(0) = "URL1"
arrSites(1) = "URL2"
arrSites(2) = "URL3"
arrSites(3) = "URL4"
arrSites(4) = "URL5"
Set objIE = CreateObject("InternetExplorer.Application")
For i = 0 To 4 Step 1
strURL = arrSites(i)
If i = 0 Then
objIE.Navigate strURL
Else
objIE.Navigate2 strURL, 2048
End If
Next i
objIE.Visible = True
Set objIE = Nothing
End Sub
Upvotes: 2
Views: 1454
Reputation: 1
As regards the 2048 in objIE.Navigate2 strURL, 2048
Extracted from Microsoft Developer Network, MSHTML Reference, IWebBrowser2
object.Navigate2(URL, Flags, TargetFrameName, PostData, Headers)
Flags [in, optional]
.. a combination of the values defined by the BrowserNavConstants enumeration
Enum BrowserNavConstants: ... navOpenInNewTab = 2048 ...
Upvotes: 0
Reputation: 2953
You could try adding a check whether IE is busy.
For i = 0 To 4 Step 1
Do While objIE.Busy
DoEvents
Loop
strURL = arrSites(i)
If i = 0 Then
objIE.Navigate strURL
Else
objIE.Navigate2 strURL, 2048
End If
Next i
Upvotes: 0