-2

I recently learned to open websites on IE through VBA excel. Now I'm trying to add code the will check if an active IE is open and if it is, it will open a new tab to navigate the website and do the same thing over again. Unfortunately, the code I have tried doesn't work. What did I do wrong?

Sub OpenIE()
Dim IE As Object
Dim site As String

Set IE = CreateObject("InternetExplorer.Application")
site = "https://www.automateexcel.com/excel/"

IE.Visible = True
IE.navigate site

Application.StatusBar = site & " " & "is loading"

Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop

Application.StatusBar = site & " " & "is loaded"

Set IE = Nothing

End Sub
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • You are trying to loop opening the same website twice in different tabs of IE? Opening the second only on successful completion of the first? – QHarr Apr 11 '18 at 09:52
  • This should help https://stackoverflow.com/questions/19933313/vba-internet-explorer-wait-for-web-page-to-load?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – FloLie Apr 11 '18 at 10:04
  • @QHarr not acctually loop, more like condition. I want my code that if I run it on the first time it will open a browser and go to the website, and when i run it for the second time it will use the same IE app to open the same website in a new tab... I'm kinda starting to get this using the "Shell.application" but for some reasons my "Do While is looping infinite". I cant debug it – John Louie Gonzales Apr 11 '18 at 10:11
  • @QHarr the code that I'm trying to make is like this in the link https://www.mrexcel.com/forum/excel-questions/553580-vba-macro-already-open-ie-window.html #4. But for some reasons the .readystate or .busy is doing an infinite loop – John Louie Gonzales Apr 11 '18 at 10:33

2 Answers2

0

This is how you can open multiple tabs in IE object programatically

Sub Test()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Navigate "https://amazon.com" '1st tab
        .Navigate "https://flipkart.com", CLng(2048) '2nd
        .Navigate "https://snapdeal.com", CLng(2048) '3rd
        .Visible = True
    End With

End Sub
teddy2
  • 382
  • 4
  • 16
0

This also works

Sub Test()
Dim IE As Object

Set IE = Nothing
Set IE = CreateObject("InternetExplorer.Application")
Set cell = Cells(1, 1)

For i = 1 To 5
IE.navigate "https://www.google.com/search?q=" & Cells(i, 1) & "&rlz=1C1CHBF_enUS828US828&oq=62654962004&aqs=chrome..69i57j69i59.95j0j4&sourceid=chrome&ie=UTF-8", CLng(2048)
IE.Visible = True
Next
End Sub
  • While this code may answer the question, it would be better to include some context, explaining how it works and when to use it. Code-only answers are not useful in the long run. [Reference](https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers) – Kim Tang Oct 15 '20 at 12:54