Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to populate google search results to worksheet in Excel?

In some cases, you may need to do some important keyword search in Google and keep the top searching result record in a worksheet which includes the title and hyperlink of the article. This article provides a VBA method to help populate google search results to a worksheet based on given keywords in cells.

Populate google search results to worksheet with VBA code


Populate google search results to worksheet with VBA code


Supposing the keywords you need to search listing in column A as below screenshot shown, please do as follows to populate the google search results of these keywords to corresponding columns with VBA code.

1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, please click Insert > Module. Then copy and paste VBA code into the code window.

VBA code: populate google search results to worksheet

Sub xmlHttp()
'Updated by Extendoffice 2018/1/30
    Dim xRg As Range
    Dim url As String
    Dim xRtnStr As String
    Dim I As Long, xLastRow As Long
    Dim xmlHttp As Object, xHtml As Object, xHtmlLink As Object
    On Error Resume Next
    Set xRg = Application.InputBox("Please select the keywords you will search in Google:", "KuTools for Excel", Selection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    xLastRow = xRg.Rows.Count
    Set xRg = xRg(1)
    For I = 0 To xLastRow - 1
        url = "https://www.google.co.in/search?q=" & xRg.Offset(I) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
        Set xmlHttp = CreateObject("MSXML2.serverXMLHTTP")
        xmlHttp.Open "GET", url, False
        xmlHttp.setRequestHeader "Content-Type", "text/xml"
        xmlHttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
        xmlHttp.send
        Set xHtml = CreateObject("htmlfile")
        xHtml.body.innerHTML = xmlHttp.ResponseText
        Set xHtmlLink = xHtml.getelementbyid("rso").getelementsbytagname("H3")(0).getelementsbytagname("a")(0)
        xRtnStr = Replace(xHtmlLink.innerHTML, "<EM>", "")
        xRtnStr = Replace(xRtnStr, "</EM>", "")
        xRg.Offset(I, 1).Value = xRtnStr
        xRg.Offset(I, 2).Value = xHtmlLink.href
    Next
    Application.ScreenUpdating = True
End Sub

3. Press the F5 key to run the code. In the popping up Kutools for Excel dialog box, please select the cells containing keywords you will search, and then click the OK button. See screenshot:

Then all search results including titles and links are populated into corresponding column cells based on keywords. See screenshot:


Related articles:



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    karmapala · 3 months ago
    The same here.

    I follow the code, by copy it then paste the code in Excel VBA module. But after running, nothing happen, column B and C still empty but there is no error though.
  • To post as a guest, your comment is unpublished.
    Gary Swann · 5 months ago
    Hi, I've followed the points to be able to pull information from a google search based on keywords and it's not bringing any results though, I've emailed support and I've been advised to put a post here because they can't help me.
    • To post as a guest, your comment is unpublished.
      Adam · 4 months ago
      I have not been able to pull anything from google either. I followed instructions exactly.