Question : Navigating through Internet Explorer Object Model in VBA

Hello,

I am writing a screen scraper in VBA / Excel.  The page I am trying to scrape has numerous tables, but I'm struggling to get the information from a specific cell within a table.  For example, I'd like to be able to get the information from table 2, Row 4, cell 3.  From the Locals window, I can drill down and see that SHDocVw.InternetExplorer.Document has numerous childnodes, which appropriately categorizes everything.  I tried to do code similar to the following, but the code fails.

Any tips would be greatly appreciated.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
Dim myie As SHDocVw.InternetExplorer
Set myie = New SHDocVw.InternetExplorer 
myie.Navigate "http://www.pageresource.com/html/table1.htm"
myie.Visible = True 
'I get an error when I try to use this kind of statement to drilldown and get the specific cell within the document
debug.print myie.Document.childNodes(2).childNodes(1).childNodes(2).innerHTML

Answer : Navigating through Internet Explorer Object Model in VBA

I am not saying this is the only way but it splits it up for you so that you can change it to other tables, rows or cells.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Dim myHTMLDoc As HTMLDocument
Dim myTable As HTMLTable
Dim myTD As HTMLTableCell
Dim myTR As HTMLTableRow
 
'get the HTML Document
Set myHTMLDoc = Me.WebBrowser0.Document
 
'get the Value History Table
Set myTable = myHTMLDoc.getElementsByTagName("Table").Item(5)
 
'The Second Row contains the 1994 information
Set myTR = myTable.getElementsByTagName("tr").Item(1)
 
'This loop gives you every cell - I think you might like to use a loop with .item(i) to only get certain cells
For Each myTD In myTR.getElementsByTagName("td")
 
Debug.Print myTD.innerText
 
Next myTD
Random Solutions  
 
programming4us programming4us