LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 1
Default Excel Macro VBA to Count Google Search Results

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?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Google Business Search Results to Excel? [email protected] Excel Discussion (Misc queries) 0 October 1st 07 10:01 PM
Google search box on excel Dileep Chandran Excel Worksheet Functions 7 November 10th 06 04:14 AM
how to set google search window on side of excel ? Ghosh Excel Discussion (Misc queries) 2 June 24th 06 07:22 PM
Sorry... no Google results! rci Excel Programming 5 April 22nd 05 03:07 PM
Google search from excel Ant[_5_] Excel Programming 1 August 31st 04 08:46 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"