baralus
04-11-2018, 04:15 AM
I just recently learn how to interact with Internet Explorer using VBA, and i have this code that I'm trying to get to work
Sub OpenNewTab()
Dim IE As Object
Dim site As String
With CreateObject("Shell.Application").Windows
If .Count > 0 Then
' Get IE
Set IE = .Item(0) ' or .Item(.Count - 1)
Else
' Create IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
End If
End With
URL = "https://www.automateexcel.com/excel/vba"
IE.navigate URL
Application.StatusBar = URL & " " & " is loading. Please wait..."
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
Application.StatusBar = URL & " " & " Loaded"
Application.Wait (Now + TimeValue("0:00:02"))
Application.StatusBar = ""
Set IE = Nothing
End Sub
the problem is when i run it, the code goes to infinite loop because of the Do While. But I needed something like Do While to ensure that the webpage is already loaded before the code continues because I'm going to add another code that will do other things on the webpage when it is loaded. Hoping someone can help out. Thank you in advanced
Sub OpenNewTab()
Dim IE As Object
Dim site As String
With CreateObject("Shell.Application").Windows
If .Count > 0 Then
' Get IE
Set IE = .Item(0) ' or .Item(.Count - 1)
Else
' Create IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
End If
End With
URL = "https://www.automateexcel.com/excel/vba"
IE.navigate URL
Application.StatusBar = URL & " " & " is loading. Please wait..."
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
Application.StatusBar = URL & " " & " Loaded"
Application.Wait (Now + TimeValue("0:00:02"))
Application.StatusBar = ""
Set IE = Nothing
End Sub
the problem is when i run it, the code goes to infinite loop because of the Do While. But I needed something like Do While to ensure that the webpage is already loaded before the code continues because I'm going to add another code that will do other things on the webpage when it is loaded. Hoping someone can help out. Thank you in advanced