This code needs to be updated as Google has slightly modified the source code. Here is the code that has been working since November 11, 2013 for everyone who needs it (a small other modification, the macro ignores the 1st row so that the column headers and search results are converted to values ββso that they are ready to be manipulated / sorted in Excel .
Public Sub ExcelGoogleSearch() Dim searchWords As String With Sheets("Sheet1") RowCount = 2 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 = "https://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, "div id=" & Chr(34) & "resultStats", vbTextCompare) + 21 If pos_1 = 21 Then NumberofResults = 0 Else pos_2 = InStr(pos_1, results_var, "result", vbTextCompare) - 1 NumberofResults = Val(Replace(Replace(Mid(results_var, pos_1, pos_2 - pos_1), ",", ""), "About", "")) End If Range("B" & RowCount) = NumberofResults RowCount = RowCount + 1 Loop End With End Sub
source share