2

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

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
mp42871
  • 191
  • 1
  • 5
  • 16
  • 1
    You will also get any open Windows Explorer window. One thing that can work is trying to cast the ie.Document to mshtml.IHtmlDocument, that will only work for an IE instance. – Hans Passant Sep 13 '11 at 19:28

1 Answers1

2

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
James
  • 36
  • 2