VBA to Loop through Links on Website Or click Next Button

PShingadia

New Member
Joined
Aug 5, 2015
Messages
47
Hi All

I'm relatively new to VBA and been struggling with the following for 2 days without much progress. If anyone can help then you will make someone today really happy!!

I have written a web scrape and got quite far but stuck with an area where I need to loop through multiple links on a site. When you click on the link it brings up another window and from that want to extract some data. This preview window also has a next button which you can click to see the next item data or you can return back to the list of original links and click on those. I would like either to work. That is access the preview window by clicking the first link and then navigate al the others by the 'Next' button or just loop all the list of links and go to the preview window these show up.

The section of code I have for this is:



Dim btnNext As HTMLSelectElement

Set Alllinks = ie.document.getElementsByTagName("A")

For Each Hyperlink In Alllinks
If Hyperlink.innerText = "View" Then
Hyperlink.Click


Application.Wait (Now + TimeValue("00:00:02"))
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

Set btNext = HTML.document.getElementById("btnNext")
btNext.Click

End If
Next Hyperlink


The above works in clicking the first link and showing the preview window but then does not loop around the others nor does it click the next button. It shows an 'Object Required' error message.

From a desperate man please help!!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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