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

use*_*406 2 vbscript

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

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

Set IE = CreateObject("InternetExplorer.Application")
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我这个.谢谢.

Ans*_*ers 5

您可以使用该Shell.Application对象查找已在运行的IE实例.

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
Run Code Online (Sandbox Code Playgroud)

以上将附加到找到的第一个实例.如果你删除Exit For它将改为附加到找到的最后一个实例.