Using VBA to IE Automation. Input error

Dzirt07

New Member
Joined
Oct 10, 2017
Messages
11
Hello

I'm trying to input address and it doesn't work

I'm using this site
https://www.latlong.net/

Please advise why am I getting an error "Object required"
The error occurred when macro is executing

Code:
IE.Document.getElementById("Es2259").Value = address



Code:
Sub Automate_IE_Load_Page()'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
    Dim brt As Variant
    
    
    'LastRow = Worksheets("tax").Cells(Worksheets("tax").Rows.Count, "C").End(xlUp).row
 
 
    For i = 2 To 3438
    
    
    address = Worksheets("GEO_LOCATION").Cells(i, 2).Value
    
    
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
 
    'Define URL
    URL = "https://www.latlong.net/"
 
    'Navigate to URL
    IE.Navigate URL
 
    ' Statusbar let's user know website is loading
    Application.StatusBar = URL & " is loading. Please wait..."
 
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.readyState = 4: DoEvents: Loop   'Do While
    Do Until IE.readyState = 4: DoEvents: Loop   'Do Until
    


 
    'Webpage Loaded
    Application.StatusBar = i
    
    IE.Document.getElementById("Es2259").Value = address
    
    
    IE.Document.getElementById("latlngspan") = Worksheets("GEO_LOCATION").Cells(i, 5)
    
Next i 
    
End Sub


Thank you for your help
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Not exactly sure what your trying to accomplish but I'm pretty sure that U don't want to create thousands of internet explorer objects within a loop. I'm pretty sure the "address" needs to be a string variable. Maybe describe your desired outcome. HTH. Dave
 
Upvote 0
Please advise why am I getting an error "Object required"
The error occurred when macro is executing

Code:
IE.Document.getElementById("Es2259").Value = address
Because the id of the element changes every time the page loads, and therefore you can't use getElementById.

Try this:

Code:
Public Sub IE_LatLong()
    
    Dim IE As Object
    Dim address As String
    
    address = "xxxx"

    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        .navigate "https://www.latlong.net/"
        While .Busy Or .readyState <> 4: DoEvents: Wend
        .document.getElementsByTagName("INPUT")(0).Value = address
        .document.getElementsByTagName("BUTTON")(0).Click
        While .Busy Or .readyState <> 4: DoEvents: Wend
    End With
    
    Set IE = Nothing
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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