I'm trying to use the code below to retrieve data from a webpage. I have my program navigate to the webpage then send the DOM to the sub I've shown below. It seems to me like this should work, but it doesn't. I've tried just about every variation possible, and I can't find anything to make it work. Any ideas that you might have would be greatly appreciated. Thanks!
Code:Sub CAMSAnalyzer(HTMLDoc As HTMLDocument) 'Use to sift through the results returned by CAMS 'and identify the relevant account information Dim AllResults As HTMLGenericElement Dim TRElements As HTMLGenericElement Dim TDElements As HTMLGenericElement Dim ClassName As String Dim Att As String Dim Val As String Dim i As Integer Dim j As Integer Dim k As Integer k = 0 j = 0 i = 0 With Range("A3").Select Set AllResults = HTMLDoc.getElementsByTagName("*") 'this is where my problem is! For Each TRElements In AllResults.getElementsByTagName("tr") For Each TDElements In TRElements.getElementsByTagName("td") If TDElements.getAttribute("class") <> Null Then ClassName = TDElements.getAttribute("class") If ClassName = "dm-attribute" Then Att = "Some Attribute" ActiveCell.Offset(i + 3, 0).Value = Att i = i + 1 End If If ClassName = "dm-value" Then Val = "Some Value'" ActiveCell.Offset(i + 3, 1).Value = Val End If End If j = j + 1 Next TDElements k = k + 1 Next TRElements End With Range("C2").Value = "j = " & j Range("C3").Value = "k = " & k End Sub




Reply With Quote