I have a large excel file with a lot of strings in Column A. I would like the exact number of Google search results in Column B (and especially the option of showing 0 results - in fact, only knowing if there either exist or not exist results would be sufficient).
I'm aware that a VBA code for this exist here taken from this website.
But I'm having the same problems as these people commenting:
i got it to work in a test a few times, but now it says run-time error '2147024891 (80070005)'
then when i debug it, it highlights search_http.send
what is wrong?
I'm not an advanced Excel user, nor a VBA programmer so some guidance would be appreciated. Maybe I'm overlooking something basic that produces this error...
Many thanks,
Mauritz
Code I'm using:
Public Sub ExcelGoogleSearch()Dim searchWords As String
With Sheets("Sheet1")
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, "resultStats>", vbTextCompare)
If pos_1 = 0 Then
NumberofResults = 0
Else
pos_2 = InStr(3 + pos_1, results_var, ">", vbTextCompare)
pos_3 = InStr(pos_2, results_var, "<nobr>", vbTextCompare)
NumberofResults = Mid(results_var, 1 + pos_2, (-1 + pos_3 - pos_2))
End If
Range("B" & RowCount) = NumberofResults
RowCount = RowCount + 1
Loop
End With
End Sub