Hi,
I have a sheet that has the street address information Columns 2-5. The rows are dynamic. I am attempting to take the data on Sheet Address Verification and have it connect to USPS site and pull back the correct USPS format on the same sheet; however, I am getting an Object error 91. Here is my code
I have a sheet that has the street address information Columns 2-5. The rows are dynamic. I am attempting to take the data on Sheet Address Verification and have it connect to USPS site and pull back the correct USPS format on the same sheet; however, I am getting an Object error 91. Here is my code
Code:
Sub USPS()Dim eRow As Long
Dim ele As Object
Dim lrow As Integer
'Dim IE As New InternetExplorer
Sheets("Address Verification").Select
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Set objie = CreateObject("InternetExplorer.Application")
lrow = ThisWorkbook.Worksheets("Address Verification").Cells(Rows.Count, 2).End(xlUp).Row
For r = 5 To lrow
myaddress = Cells(r, 2).Value
mycity = Cells(r, 3).Value
mystate = Cells(r, 4).Value
myzipcode = Cells(r, 5).Value
'myaddress = Range("a2").Value
'mycity = Range("c2").Value
'mystate = Range("d2").Value
'myzipcode = Range("e2").Value
With objie
.Visible = True
.navigate "https://tools.usps.com/go/ZipLookupAction!input.action"
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
Set what = .document.getElementsByName("tAddress")
what.Item(0).Value = myaddress
Set ZipCode = .document.getElementsByName("tCity")
ZipCode.Item(0).Value = mycity
Set zipcode1 = .document.getElementsByName("sState")
zipcode1.Item(0).Value = mystate
Set zipcode2 = .document.getElementsByName("Zzip")
zipcode2.Item(0).Value = myzipcode
.document.getElementById("lookupZipFindBtn").Click
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
For Each ele In .document.all
Select Case ele.className
Case "address1 range"
Worksheets("Address Verification").Cells(r, 7).Value = ele.innerText
Case "city range"
Worksheets("Address Verification").Cells(r, 8).Value = ele.innerText
Case "state range"
Worksheets("Address Verification").Cells(r, 9).Value = ele.innerText
Case "zip"
Worksheets("Address Verification").Cells(r, 10).Value = ele.innerText
Case "zip4"
Worksheets("Address Verification").Cells(r, 10).Value = ele.innerText
End Select
'
Next ele
End With
Next r
Set objie = Nothing
Set ele = Nothing
Set IE = Nothing
'IE.Quit
End Sub