Excel Macro VBA to Count Google Search Results

jeffreytp

New Member
Joined
Jun 7, 2012
Messages
2
I have a keyword in A1
I want to run a Google search of A1 and count the results and put that # in B1

For Example, if A1= how to make small seats smaller
The Google Search result count is 140,000,000
I want to put 140,000,000 into B1

repeat for all the values in column A

Here is a Macro code I found, but when I run it I get this Error:

Run-time error '-2147024891 (80070005)':
Access is denied


When I debug, it highlights:
search_http.Send


<code id="questionViewInlineCode10-27747965-1"></code>
Code:
Public Sub ExcelGoogleSearch()
Dim searchwords As String
Dim search_url As String
Dim search_http As Object
Dim results_var As Variant, NumberOfResults As Variant
Dim rowcount As Long
Dim pos_1 As Integer, pos_2 As Integer, pos_3 As Integer
With Sheets("Sheet1")
.Columns(2).ClearContents
rowcount = 1
Do While .Range("A" & rowcount) <> ""
searchwords = .Range("A" & rowcount).Value
' Get keywords and validate by adding + for spaces between
searchwords = Replace$(searchwords, " ", "+")
' Obtain the source code for the Google-searchterm webpage
search_url = "http://www.google.com/search?hl=en&q=" & searchwords & "&meta="""
Set search_http = CreateObject("MSXML2.XMLHTTP")
search_http.Open "GET", search_url, False
search_http.Send
results_var = search_http.ResponseText
Set search_http = Nothing
' Find the number of results and post to sheet
pos_1 = InStr(1, results_var, "b> of", vbTextCompare)
pos_2 = InStr(3 + pos_1, results_var, ">", vbTextCompare)
pos_3 = InStr(pos_2, results_var, "<", vbTextCompare)
NumberOfResults = Mid(results_var, 1 + pos_2, (-1 + pos_3 - pos_2))
Range("B" & rowcount) = NumberOfResults
rowcount = rowcount + 1
Loop
End With
End Sub

I am running Excel 2010 & IE9

Anyone have a solution?
 
Last edited:

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