DOM IE Automation Error

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
I am attempting to set up some IE automation; however, I am running into an error where it states that the object is not supported. Here is where the code is throwing an error
Code:
.document.GetElementsByName("byaddress").Click

I might be calling the wrong element. The a title="byaddress"

Here is my entire code:
Code:
Sub USPS()
Dim eRow As Long
Dim ele As Object




'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")


For r = 5 To 9


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("tState")
zipcode1.Item(0).Value = mystate
Set zipcode2 = .document.getElementsByName("tZip-byaddress")
zipcode2.Item(0).Value = myzipcode


.document.getElementsByName("byaddress").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, 11).Value = ele.innerText


End Select
'
Next ele
End With


Next r
Set objie = Nothing
Set ele = Nothing
Set IE = Nothing
    
'IE.Quit




End Sub
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
getElementsByName returns an array of elements (the letter 's' in Elements is significant - contrast with getElementById which returns a single element), therefore you have to specify the array index of the element you want. Assuming you want the first element with the name "byaddress":

Code:
.document.GetElementsByName("byaddress")(0).Click
 
Upvote 0
Hi John_w,

That makes complete sense. Thank you. I took your approach to get the element by the ID and this is the ID: a class="btn-primary" id="zip-by-address" role="button" href="" Find

This is the update I made to my code:
Code:
myaddress = Cells(r, 2).Valuemycity = 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("tState")
zipcode1.Item(0).Value = mystate
Set zipcode2 = .document.getElementsByName("tZip-byaddress")
zipcode2.Item(0).Value = myzipcode


.document.getElementsByID("zip-by-address").Click

The error that it is throwing is 438 Object doesn't support this property or method.

Thank you again for looking at this for me.
 
Last edited:
Upvote 0
You are awesome! Thank you so much. Now I am struggling with getting the results back into excel. The html code on the element is div class="zipcode-result-address" p p p 123 Fake st ste 102 p San Diego CA strong 92215-2645 /strong

My vba code trying to pull it in is this:
Code:
Do While .Busy Or _.readyState <> 4
DoEvents
Loop
Set searchres = .document.getElementById("show-results-address")


ThisWorkbook.Worksheets("Address Verification").Cells(r, 6) = searchres.innerText


End With


Next r
This is r:
Code:
For r = 5 To 9
Currently the code is just updating IE; however, the results are not coming back to Excel.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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