引用Internet Explorer - 使用Internet Explorer对象模型

时间:2013-07-29 11:00:25

标签: vbscript

我想在运行时创建一个Internet Explorer对象,我需要它来引用或查找已在当前会话中打开的浏览器对象(IE)。

使用以下代码作为Start up创建一个新的Internet Explorer对象并打开一个浏览器并引用它。但是如何创建一个Internet Explorer对象,它可以帮助我们识别会话中打开的现有浏览器,而不是打开新的浏览器窗口。

Set IE = CreateObject("InternetExplorer.Application")

有人可以帮我解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:5)

您可以将Shell.Application对象用于find an already running IE instance

Set sh = CreateObject("Shell.Application")
For Each wnd In sh.Windows
  If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
    Set ie = wnd
    Exit For
  End If
Next

以上将附加到找到的第一个实例。如果您删除Exit For,则会将其附加到找到的最后一个实例。