SHDocVw.在shellWindows中返回太多对象



下面的代码行返回几个InternetExplorer对象,即使我只有一个浏览器窗口打开(没有选项卡),只有一个iexplorer .exe进程运行。我如何只得到打开的浏览器窗口对象?

For Each ie As SHDocVw.InternetExplorer In shellWindows

这可能有帮助

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

最新更新