Hello,
I am having trouble coming up with a macro that searches google based on a cell value, then returns the Google review score. I tried modifying the below code to suit my needs but keep getting a Run-time error 91 Object variable or With block variable not set. Any help would be greatly appreciated.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub goog_rev()
Dim IE As New InternetExplorer, html As HTMLDocument, ele As Object
With IE
.Visible = True
.navigate "http://www.google.com/"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
Set sht = Sheets("Sheet2")
End With
html.getElementById("lst-ib").Value = sht.Range("A2")
html.getElementById("btnK").Click
Application.Wait Now + TimeValue("00:00:05")
html.getElementsByClassName("rc")(0).getElementsByTagName("a")(0).Click
Application.Wait Now + TimeValue("00:00:05")
For Each ele In html.getElementsByClassName("0b2kfd")
With ele.getElementsByClassName("rtng")
'If .Length Then r = r + 1: Cells(r, 1) = .Item(0).innerText
sht.Range("B2") = .Item(0).innerText
End With
Next ele
IE.Quit
End Sub</code>
I am having trouble coming up with a macro that searches google based on a cell value, then returns the Google review score. I tried modifying the below code to suit my needs but keep getting a Run-time error 91 Object variable or With block variable not set. Any help would be greatly appreciated.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub goog_rev()
Dim IE As New InternetExplorer, html As HTMLDocument, ele As Object
With IE
.Visible = True
.navigate "http://www.google.com/"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
Set sht = Sheets("Sheet2")
End With
html.getElementById("lst-ib").Value = sht.Range("A2")
html.getElementById("btnK").Click
Application.Wait Now + TimeValue("00:00:05")
html.getElementsByClassName("rc")(0).getElementsByTagName("a")(0).Click
Application.Wait Now + TimeValue("00:00:05")
For Each ele In html.getElementsByClassName("0b2kfd")
With ele.getElementsByClassName("rtng")
'If .Length Then r = r + 1: Cells(r, 1) = .Item(0).innerText
sht.Range("B2") = .Item(0).innerText
End With
Next ele
IE.Quit
End Sub</code>