J
Jim
I am trying to read a the Post Office web page after I submit a zip code. The
following is what I have copied from anther site and have modified. The
orginal code had "Set objTable = objDoc.getElementById("idTable")" to
"Set objTable = objDoc.getElementsByTagName("table")" due to the table not
having an id. Being new at programming, I'm not sure as to what I'm doing
wrong.
It will work until I get to Set objCell = objTable.Rows(c), then I take an
error. My
code is as follows:
Sub MFHLookup()
Dim objIE As Object
Dim objDoc As Object
Dim objTable As Object
Dim objCell As Object
Dim FormValue As String
Dim Anymore As Boolean
Dim Found As Boolean
Dim c
Do Until Anymore = True
FormValue = ActiveCell.Value
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
objIE.Navigate "http://zip4.usps.com/zip4/citytown_zip.jsp"
Do While objIE.Busy: DoEvents: Loop
Do While objIE.ReadyState <> 4: DoEvents: Loop
objIE.Visible = True
With objIE
.Document.getElementById("zip5").Focus
.Document.getElementById("zip5").Value = "30339"
.Document.getElementById("submit").Click
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
End With
Set objDoc = objIE.Document
Set objTable = objDoc.getElementsByTagName("table")
c = 20
Set objCell = objTable.Rows(c)
If Trim(objCell.InnerText) <> "30339" Then
Do Until Found = True
c = c + 1
Set objCell = objTable.Cells(c)
If Trim(objCell.InnerText) <> "30339" Then
Found = False
Else
Found = True
End If
Loop
Else
End If
c = c + 1
Set objCell = objTable.Cells(c)
ActiveCell.Offset(0, 1).Value = Trim(objCell.InnerText)
objIE.Quit
Set objIE = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objCell = Nothing
ActiveCell.Offset(1, 0).Select
Anymore = IsEmpty(ActiveCell.Value)
Loop
ActiveWorkbook.Save
End Sub
Thanks for the help,
Jim
following is what I have copied from anther site and have modified. The
orginal code had "Set objTable = objDoc.getElementById("idTable")" to
"Set objTable = objDoc.getElementsByTagName("table")" due to the table not
having an id. Being new at programming, I'm not sure as to what I'm doing
wrong.
It will work until I get to Set objCell = objTable.Rows(c), then I take an
error. My
code is as follows:
Sub MFHLookup()
Dim objIE As Object
Dim objDoc As Object
Dim objTable As Object
Dim objCell As Object
Dim FormValue As String
Dim Anymore As Boolean
Dim Found As Boolean
Dim c
Do Until Anymore = True
FormValue = ActiveCell.Value
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
objIE.Navigate "http://zip4.usps.com/zip4/citytown_zip.jsp"
Do While objIE.Busy: DoEvents: Loop
Do While objIE.ReadyState <> 4: DoEvents: Loop
objIE.Visible = True
With objIE
.Document.getElementById("zip5").Focus
.Document.getElementById("zip5").Value = "30339"
.Document.getElementById("submit").Click
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
End With
Set objDoc = objIE.Document
Set objTable = objDoc.getElementsByTagName("table")
c = 20
Set objCell = objTable.Rows(c)
If Trim(objCell.InnerText) <> "30339" Then
Do Until Found = True
c = c + 1
Set objCell = objTable.Cells(c)
If Trim(objCell.InnerText) <> "30339" Then
Found = False
Else
Found = True
End If
Loop
Else
End If
c = c + 1
Set objCell = objTable.Cells(c)
ActiveCell.Offset(0, 1).Value = Trim(objCell.InnerText)
objIE.Quit
Set objIE = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objCell = Nothing
ActiveCell.Offset(1, 0).Select
Anymore = IsEmpty(ActiveCell.Value)
Loop
ActiveWorkbook.Save
End Sub
Thanks for the help,
Jim