VBA Internet Explorer - following link to new window

blgross07

New Member
Joined
Jul 23, 2015
Messages
5
Hello,

I am having some issues with data scraping a website table I am interested in. The reason is because one of the links I click on in the process opens a new IE tab. How do I follow the link to the new window via VBA? Current code I have is below.

Code:
Sub Button1_Click()
Dim ie As Object


Set ie = CreateObject("InternetExplorer.Application")


With ie


.Visible = True
.navigate ("website")


While ie.readyState <> 4: DoEvents: Wend


ie.document.forms(0).all("SheetContentPlaceHolder_c_search1_btnNextSale").Click


End With
 
Application.Wait Now + #12:00:01 AM#



ie.document.forms(0).all("SheetContentPlaceHolder_C_searchresults_lbPrint").Click

'This button click opens new window


End Sub



Thanks,
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Loop through Shell.Windows, looking for a specific property of the new tab (e.g. its IE.LocationURL, or IE.LocationName, or maybe some text in IE.document.innerText, etc.). There should be example code on the forum - I think ZVI has a very good procedure.

Or put your code in sheet module and declare the IE object like this:
Code:
Public WithEvents IE As InternetExplorer
and catch the new tab in the IE_NewWindow2 event. You must set the reference (via Tools->References in the VBA editor) to Microsoft Internet Controls. This technique can also be done in a class module, but a bit more code is required to instantiate an object of the class.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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