+ Reply to Thread
Results 1 to 1 of 1

Controlling Child Window in IE

Hybrid View

rlee12 Controlling Child Window in IE 03-28-2013, 09:33 PM
  1. #1
    Registered User
    Join Date
    02-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    21

    Controlling Child Window in IE

    I have been searching for a while for a program to control a popup window (child window) when I click on a search button on the parent page. I keep coming back to the following code.

    Option Explicit
    
    Public WithEvents IE1 As InternetExplorer
    Public IE2 As InternetExplorer
    
    
    Private Sub ParseReportFromWeb()
    
    Dim sURL As String
    Dim ElementCol As IHTMLElementCollection
    Dim link As HTMLAnchorElement
    
    'Example web site which has links which open in a new window
    sURL = "http://www.dh.gov.uk/en/index.htm"
    
    Set IE1 = New InternetExplorer
    Set IE2 = Nothing
    
    With IE1
        .navigate sURL
        .Visible = True  'allows for viewing the web page
    End With
    
    ' loop until the page finishes loading
    Do While IE1.Busy: Loop
    
    Set ElementCol = IE1.document.getElementsByTagName("a")
    
    'Find and click the 'Videos (opens new window)' link
    For Each link In ElementCol
        If InStr(link.innerText, "Videos") = 1 Then
            link.Click
            Exit For
        End If
    Next link
    
    'Ensure new window has been created
    Do While IE2 Is Nothing: Loop
    
    Do While IE2.Busy: Loop
     
    'Click first link in the new window
    Set ElementCol = IE2.document.getElementsByTagName("a")
    Set link = ElementCol(0)
    link.Click
    
    End Sub
    
    Private Sub IE1_NewWindow2(ppDisp As Object, Cancel As Boolean)
        Set IE2 = New InternetExplorer
        Set ppDisp = IE2.Application
        Debug.Print "NewWindow2"
    End Sub
    However, I cannot get it to work. I am putting it in a class module and loading Microsoft Internet Controls and HTML Objects Library. I keep getting an error message that the program isn't hooked to IE. When does the program above "hook" to the child window so it can be manipulated? How do I run all of the code above... i.e. there are multiple programs? Where do I put code to control the child window???
    Last edited by rlee12; 03-28-2013 at 09:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1