PDA

View Full Version : Not able to access elements from a webpage



musicgold
04-11-2011, 03:20 PM
Hi,

I am trying to access the links in this webpage (http://www.hr-reit.com/finance/quarter.asp) using VBA, Though I am able to get the collection of the objects I want, the For Next loop doesn’t work. The htmlinput is empty. So, control doesn't enter the loop.

I tested the same code for another page (http://www.hr-reit.com/finance/quarterly/quarterchild.asp) of this website and it works fine. What is wrong with this page?

Here is my code



….
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("A")

For Each htmlInput In htmlColl

If (Left(htmlInput.getAttribute("innerText"), 11) = "Acrobat PDF") Then
Str = htmlInput.getAttribute("href")
counter = counter + 1
ActiveCell.Offset(counter, 0).Value = Str

End If

Next

Next

….