vb.netvisual-studio-2008internet-explorershdocvw

SHDocVw.InternetExplorer In shellWindows returning too many objects


The following line of code return several InternetExplorer objects even though I have only one browser window open (no tabs) and only one iexplore.exe process running. How do I only get the open browser window object?

For Each ie As SHDocVw.InternetExplorer In shellWindows


Solution

  • This may help

    Dim objShellWindows As New SHDocVw.ShellWindows
    Dim rVal As SHDocVw.InternetExplorer
        For Each rVal In objShellWindows
            Debug.Print TypeName(rVal.Document)
            If TypeName(rVal.Document) = "HTMLDocument" Then
                If rVal.Name = "Windows Internet Explorer" Then
                    rVal.Visible = False
                    rVal.Visible = True
                    Set ie = rVal
                    ie.Quit
                    Set ie = Nothing
                End If
            End If
        Next rVal