I am trying to get an existing (open) IE window to load a new URL via ie.Navigate
.
Below is my worksheet code which loads a website on click of a button:
Private Sub Sendit_Click()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.yahoo.com"
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE
GetIE
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
This code is in my module:
Function GetIE()
Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Set shellWins = New ShellWindows
If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = True
End If
IE.navigate "http://www.google.com"
Set shellWins = Nothing
Set IE = Nothing
End Function
IE doesn't navigate to http://www.google.com.
As a similar/adapted alternative, here's a favorite function of mine.
This function returns an object representing the existing
InternetExplorer
instance if there is one, otherwise a newly-created instance.More information and example here.