Excel Macro VBA to Count Google Search Results

J

jeffreytp

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top