引用 Internet Explorer - 使用 Internet Explorer 对象模型 [英] Referring Internet Explorer - Using Internet Explorer Object Model

查看:68
本文介绍了引用 Internet Explorer - 使用 Internet Explorer 对象模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanted to create a Internet Explorer object in Run Time and I need that to refer or find an browser object (IE) which is already opened in the current session.

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

Using the below code as Start up creates a new internet explorer object and opens a browser and refers to the same. But how to Create an internet explorer object which would help us identify an existing Browser opened in the session and not to open a new browser window.

Set IE = CreateObject("InternetExplorer.Application")

谁能帮我解决这个问题.谢谢.

Could anyone help me on this. Thank you.

推荐答案

您可以使用 Shell.Application 对象来找到一个已经运行的 IE 实例.

You can use the Shell.Application object to 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,它将改为附加到找到的最后一个实例.

The above will attach to the first instance found. If you remove the Exit For it will instead attach to the last instance found.

这篇关于引用 Internet Explorer - 使用 Internet Explorer 对象模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆