VBA Looping through Links on Website

PShingadia

New Member
Joined
Aug 5, 2015
Messages
47
Hi All:

Been struggling all day to write some VBA to loop through links on HTML site but keeps failing and showing error code 0. Please help!! I have the following:


Set HTML = ie.document
Set ElementCol = HTML.getElementsByClassName("ViewLink")


For Each link In ElementCol
If link.innerText = "ViewLink" Then
link.Click
End If
Next link

There are about 10 links and the script for three - in no order - are as follows:


A class=ViewLink id=MainContent_GridView1_btnView_1 href="javascript:__doPostBack('ctl00$MainContent$GridView1$ctl03$btnView','')">View</A

A class=ViewLink id=MainContent_GridView1_btnView_0 href="javascript:__doPostBack('ctl00$MainContent$GridView1$ctl02$btnView','')">View</A

A class=ViewLink id=MainContent_GridView1_btnView_6 href="javascript:__doPostBack('ctl00$MainContent$GridView1$ctl08$btnView','')">View</A



PLease let me know how this should be written


Thanks
 
Last edited:

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.

Forum statistics

Threads
1,223,963
Messages
6,175,656
Members
452,664
Latest member
alpserbetli

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