user1925406
user1925406

Reputation: 733

Referring Internet Explorer - Using Internet Explorer Object Model

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.

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.

Upvotes: 2

Views: 1879

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200203

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

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

Upvotes: 5

Related Questions