How to assign an object to a child IE window

J

Jason

Hi,

I am trying to automate a web form-filling process, and when the form is
submitted a child window of IE pops up with the results...I am having a lot
of trouble assigning a new object to this new instance of IE (so that I can
further manipulate this in my VBA code).

Could someone please detail the code required to do this? So far I have:

---------------------
Sub AutoIE()

Dim IE1 As InternetExplorer
Dim IE2 As InternetExplorer

Set IE1 = New InternetExplorer


' Do my stuff with IE1 and submit the form
'....
' New child window pops up here


'< Need your help here on how to set IE2 to the new child window (with IE1
still
' open/running) >


End Sub
 
T

Tim Williams

See "GetIE" below - it will search for an open IE window which has a URL
beginning with the string parameter "sLocation".

You'll just need to fing the URL of the pop-up window (try Ctrl-N...)

Tim.



Sub test2()
Dim o


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


If Not o Is Nothing Then
MsgBox o.document.body.innerHTML
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

Jason

Hi Tim,

Thanks! It works like a charm- you're a lifesaver!! :)

Jason.

Tim Williams said:
See "GetIE" below - it will search for an open IE window which has a URL
beginning with the string parameter "sLocation".

You'll just need to fing the URL of the pop-up window (try Ctrl-N...)

Tim.



Sub test2()
Dim o


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


If Not o Is Nothing Then
MsgBox o.document.body.innerHTML
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
 

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