Using VB2008 to navigate to IE window

I am using the following code to navigate to a URL in IE8, however it opens a new IE window each time which I dont want, any advice:

        Dim MyExplorer As SHDocVw.InternetExplorer
        MyExplorer = New InternetExplorer
        MyExplorer.Navigate(URL)
Dave FyfeTechnicianAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Adding to kaufmed's answer:
Imports SHDocVw
Public Class Form1

    Private WithEvents MyExplorer As InternetExplorer = Nothing

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Navigate(TextBox1.Text)
    End Sub

    Private Sub Navigate(ByVal URL As String)
        If IsNothing(MyExplorer) Then
            MyExplorer = New InternetExplorer
            MyExplorer.Visible = True
        End If
        MyExplorer.Navigate(URL)
    End Sub

    Private Sub MyExplorer_OnQuit() Handles MyExplorer.OnQuit
        MyExplorer = Nothing
    End Sub

End Class

Open in new window

0
 
käµfm³d 👽Commented:
If you set "MyExplorer" to a new object every time, then I assume it is creating a new window every time. Try widening the scope of "MyExplorer" and only calling the Navigate() method where you are currently calling it. Something like:
private MyExplorer As New SHDocVw.InternetExplorer()

Public Sub GoToAddress(ByVal address As String)
    Me.MyExplorer.Navigate(address)
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.