how to control IE pop-up window

niftywonz

New Member
Joined
Feb 12, 2017
Messages
9
I'm Trying to get control of the IE pop-up window in my VBA excel project with no success. Could someone please explain to me how to do this, I have looked around the internet but have not found a solution. When I use the debug print command in the code it tells me the pop-up window address bar is false and assuming it should be true. This is the last leg of my project and I would be very grateful to anyone who could provide some feedback.

Option Explicit
Sub mainproject()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLdoc As MSHTML.IHTMLDocument


Dim shell As SHDocVw.ShellWindows


Set shell = New SHDocVw.ShellWindows



IE.Visible = True
IE.navigate "http://www.flashscore.com/basketball/usa/nba/"

Do While IE.readyState <> READYSTATE_COMPLETE
Application.Wait Now + TimeValue("00:00:01")
Loop
'Debug.Print IE.LocationName, IE.LocationURL

IE.document.getElementById("fs-summary-fixtures").Children(0).Children(2).Children(1).Children(2).Click

For Each IE In shell
If IE.LocationURL = "http://www.flashscore.com/match" Then
'Set IE =

Exit For
End If
Debug.Print IE.LocationName, IE.LocationURL, IE.AddressBar, IE.Application

Next
Set IE = Nothing
Set shell = Nothing

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Your If IE.LocationURL = statement is checking for a specific string so is not finding the pop-up window; use Instr instead to see if the URL contains a specific substring:
Code:
    Dim IE2 As SHDocVw.InternetExplorer
    Set IE2 = Nothing
    For Each IE In shell
        Debug.Print IE.LocationName, IE.LocationURL
        If InStr(IE.LocationURL, "http://www.flashscore.com/match") Then
            Set IE2 = IE
            Exit For
        End If
    Next
    
    If Not IE2 Is Nothing Then
        While IE2.Busy Or IE2.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        MsgBox IE2.LocationURL & vbNewLine & IE2.LocationName
    End If
 
Last edited:
Upvote 0
Just wondering if there is a way to tell if I'm actually in control of the pop-up window? In the pop-up window, I want to click on the head-2-head button and I try to find it with the debug print command "Debug.Print IE2.document.getElementsByTagName("a").ID" but I'm only getting an error
 
Upvote 0
The IE2 object is the pop-up window. To click the H2H link
Code:
    Dim HTMLdoc As MSHTML.HTMLDocument   'change your Dim - not IHTMLDocument
        Set HTMLdoc = IE2.document
        HTMLdoc.getElementById("a-match-head-2-head").Click
What do you mean by "the pop-up window as False"? Do you mean the AddressBar property is False? I've never used AddressBar, but see https://msdn.microsoft.com/en-us/office/aa752048(v=vs.100) as this property relates to the address box and other IE controls and buttons.
 
Last edited:
Upvote 0
John.W,
Thank you for your time and effort, I really do appreciate it.
If I could please trouble you once again as I'm stuck once again. As you will able to see in the code below I want to navigate to the H2H page and from the match summary page, I would then like to get the scores from the last 10 games played H2H between the 2 teams listed and put the scores into my spreadsheet in separate cells. It seems like after the click command the page location and URL are still reading the match summary page which won't allow me to extract the scores from the H2H overall page to put into my spreadsheet. sorry for any inconvenience but I really do appreciate your time and effort I am a beginner and this is my 1st project and I'm grateful for the lesson being learned.

Option Explicit
Sub mainproject()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLdoc As MSHTML.HTMLDocument
Dim IE2 As SHDocVw.InternetExplorer
Dim ele As Object




Dim shell As SHDocVw.ShellWindows

Set HTMLdoc = IE2


Set shell = New SHDocVw.ShellWindows
Set IE2 = Nothing

IE.Visible = True
IE.navigate "http://www.flashscore.com/basketball/usa/nba/"

Do While IE.readyState <> READYSTATE_COMPLETE
Application.Wait Now + TimeValue("00:00:03")
Loop
'Debug.Print IE.LocationName, IE.LocationURL

IE.document.getElementById("fs-summary-fixtures").Children(0).Children(2).Children(1).Children(2).Click

Do While IE.readyState <> READYSTATE_COMPLETE
Application.Wait Now + TimeValue("00:00:01")
Loop

For Each IE In shell
'Debug.Print IE.LocationName, IE.LocationURL
If InStr(IE.LocationURL, "http://www.flashscore.com/match") Then
Set IE2 = IE
Exit For
End If
Next

If Not IE2 Is Nothing Then
While IE2.Busy Or IE2.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
'Debug.Print IE2.LocationURL & vbNewLine & IE2.LocationName & IE2.AddressBar & IE2.Application

End If




IE2.document.getElementById("a-match-head-2-head").Click



Debug.Print IE2.LocationURL & vbNewLine & IE2.LocationName





End Sub
 
Upvote 0
if you could let me know if the debug print locationURL statement should be printing out as the previous page "match summary" or the "H2H overall" this has me confused not knowing why debug print tells me the locationURL it is still on the previous page after the click command
 
Upvote 0
After a .Click or .Navigate you normally have to wait for the new page to load. Try putting a breakpoint (F9 key) on the last Debug.Print line, run the code to that line, wait a few seconds and then execute the line. The locationURL should be the correct URL.
 
Upvote 0
That worked thank you. I was wondering would a "do while busy", or a "while busy loop" work the same way?
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top