This macro (number of Google search results) worked fine but about 2 months ago it stopped working. In column A word to search e.g. "Microsoft" and in column B should the number of search results appear.
Has something changed in Google? Thanks in advance.
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.au/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)
pos_2 = InStr(3 + pos_1, results_var, ">", vbTextCompare)
pos_3 = InStr(pos_2, results_var, "<nobr>", vbTextCompare)
If pos_1 <> 0 Then
NumberofResults = Mid(results_var, 1 + pos_2, (-1 + pos_3 - pos_2))
Range("B" & RowCount) = NumberofResults
Else
Range("B" & RowCount) = 0
End If
RowCount = RowCount + 1
' Waits 5 seconds
Application.Wait Time + TimeSerial(0, 0, 4)
' Continues here after pause
Loop
End With
End Sub
Moderator Note:
Pls use code tags around your code next time as per forum rules.
Bookmarks