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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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