Making a Web Query Compatible with Excel 2003

ransomedbyfire

Board Regular
Joined
Mar 9, 2011
Messages
121
I came across the following piece of code; and it seems to work beautifully in Excel 2007. But, in Excel 2003, it doesn't seem to be pulling the right information. However, I don't have a copy of Excel 2003 of my own. Can someone help me figure out what's going wrong in Excel 2003? Thanks!

Code:
Sub GetTableRow()
   
    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim ieTbl As Object
    Dim i As Long, j As Long
   
    Const sURL As String = "http://finance.yahoo.com/loan"
   
    'Create new IE instance
   Set ieApp = New InternetExplorer
   
    'Go to url
   ieApp.Visible = True
    ieApp.Navigate sURL
   
    'Wait for page to load
   Do
        DoEvents
    Loop Until ieApp.ReadyState = READYSTATE_COMPLETE
   
    Set ieDoc = ieApp.Document
   
    'Loop through all the elements in the document via the 'all' property
   For i = 0 To ieDoc.all.Length - 1
        'Only look at tables
       If TypeName(ieDoc.all(i)) = "HTMLTable" Then
            Set ieTbl = ieDoc.all(i)
            'I want to check the 3rd row (.Rows(2)) and will get an error if there
           'are less than three rows.
           If ieTbl.Rows.Length > 2 Then
                'Here's the text in the first cell of the third row that tells me
               'I have the right table
      '         If ieTbl.Rows(2).Cells(0).innertext = "15-yr Fixed" Then
                    'Loop through the cells and write to the sheet
                   For j = 0 To ieTbl.Rows(2).Cells.Length - 1
                        Sheet1.Cells(1, j + 1).Value = ieTbl.Rows(2).Cells(j).innertext
                    Next j
      '          End If
            End If
        End If
    Next i

    'Alternative method - when you figure out that i = 132 in the above loop
   'you can refer to that element directly.  But beware, web sites change and
   'they don't have the decency to even call you.
   
'    Set ieTbl = ieDoc.all(132)
'    For j = 0 To ieTbl.Rows(2).Cells.Length - 1
'        Sheet1.Cells(1, j + 1).Value = ieTbl.Rows(2).Cells(j).innertext
'    Next j
'
   ieApp.Quit
    Set ieApp = Nothing
   
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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