greyangel
08-09-2017, 08:25 AM
I am trying to search a database for certain locations using VBA. Below is my code. This is my first time using VBA to search an online directory. I keep getting a runtime error. Also attached is what I am trying to do.
Sub SearchGoogle()
Dim ie As Object
Dim form As Variant
Dim button As Variant
Dim LR As Integer
Dim var As String
Dim var1 As Object
LR = Cells(Rows.Count, 1).End(xlUp).Row
For x = 1 To LR
var = Cells(x).Value
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
With ie
.Visible = True
.navigate "https://www.applied.com/apps/directory/org/search.do"
While Not .readyState = READYSTATE_COMPLETE
Wend
End With
'Wait some to time for loading the page
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
'THIS IS THE PART WHERE IT ERRORS OUT ON ME ("Automation error: The object invoked has disconnected from its clients.
ie.document.getElementBytagname("loc").Value = var
'Here we are clicking on search Button
Set form = ie.document.getElementsByTagName("form")
Application.Wait (Now + TimeValue("0:00:02"))
Set button = form(0).onsubmit
form(0).submit
'wait for page to load
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
Set var1 = ie.document.getElementByid("resultStats")
Cells(x, 2).Value = var1.innerText
Next
End Sub
Sub SearchGoogle()
Dim ie As Object
Dim form As Variant
Dim button As Variant
Dim LR As Integer
Dim var As String
Dim var1 As Object
LR = Cells(Rows.Count, 1).End(xlUp).Row
For x = 1 To LR
var = Cells(x).Value
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
With ie
.Visible = True
.navigate "https://www.applied.com/apps/directory/org/search.do"
While Not .readyState = READYSTATE_COMPLETE
Wend
End With
'Wait some to time for loading the page
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
'THIS IS THE PART WHERE IT ERRORS OUT ON ME ("Automation error: The object invoked has disconnected from its clients.
ie.document.getElementBytagname("loc").Value = var
'Here we are clicking on search Button
Set form = ie.document.getElementsByTagName("form")
Application.Wait (Now + TimeValue("0:00:02"))
Set button = form(0).onsubmit
form(0).submit
'wait for page to load
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
Set var1 = ie.document.getElementByid("resultStats")
Cells(x, 2).Value = var1.innerText
Next
End Sub