VBA Website Autofill

jkteebs

New Member
Joined
Aug 3, 2016
Messages
5
Hey Everyone,

I've created a VBA code that will automatically populate fields within the website, but I'm having troubles trying to figure out the code to select a state from the dropdown list on the website. I also can't seem to figure out the code to then click on the "Find" button once the fields are populated. Here's what I have so far that doesn't seem to be working:

Code:
Sub Find_ZipCode()


Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "https://tools.usps.com/go/ZipLookupAction!input.action?mode=1&refresh=true"
IE.Navigate URL


    Do
    DoEvents
    Loop Until IE.readyState = 4


    Call IE.document.getElementById("tAddress").SetAttribute("value", "217 E Rockingham Dr")
    Call IE.document.getElementById("tCity").SetAttribute("value", "Eagle")
    
    With IE.document.getElementById("sState")
        For i = 0 To .Length - 1
            If .Item(i).Value = "ID - Idaho" Then
                .Item(i).Selected = True
            Exit For
        End If
    Next
    End With
    
    Call IE.document.getElementById("Zzip").SetAttribute("value", "83616")
    
    Set AllHyperLinks = IE.document.getElementsByTagName("A")
        For Each hyper_link In AllHyperLinks
            If ID = "lookupZipFindBtn" Then
                hyper_link.Click
            Exit For
        End If
    Next
        
End Sub

Any help would be much appreciated. Thanks!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,422
Messages
6,124,808
Members
449,191
Latest member
rscraig11

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