Connecting to an existing IE instance.

J

J Streger

I have a procedure that opens a web page and automates a download. The
download it automates opens a new explorer instance that remains after the
code has finished. I have a handle on the explorer instance I opened but I
need to know how I can run through all open IE instances on the computer, so
I can close the particular instances down once the procedure finishes. Any
help on this would be appreciated. Thanks.
 
T

Tim Williams

Try this.

Tim


'*******************************************
Sub Tester()
Dim o

Set o = GetIE("http://www.yahoo.com")

If Not o Is Nothing Then
o.Quit
Else
MsgBox "No Yahoo page found"
End If

End Sub


Function GetIE(sLocation As String) As Object

Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object

Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

For Each o In objShellWindows
sURL = ""
On Error Resume Next
'check the URL and if it's the one you want then
' assign it to the return value
sURL = o.document.Location
On Error GoTo 0
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o

Set GetIE = retVal

End Function
'##############################################
 
J

J Streger

Thank a bunch.

I think it's about time to learn about the different classes as I see myself
using the createobject function more and more.
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top