VBA to google search based on cell value

excelbeg

New Member
Joined
May 16, 2017
Messages
4
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>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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