Note: The other languages of the website are Google-translated. Back to English
English English

Jak naplnit výsledky vyhledávání Google do listu v aplikaci Excel?

V některých případech možná budete muset provést nějaké důležité vyhledávání klíčových slov v Google a uchovat záznam o výsledcích nejvyššího vyhledávání v listu, který obsahuje název a hypertextový odkaz na článek. Tento článek poskytuje metodu VBA, která pomáhá naplnit výsledky vyhledávání google do listu založeného na daných klíčových slovech v buňkách.

Naplňte výsledky vyhledávání Google do listu kódem VBA

Naplňte výsledky vyhledávání Google do listu kódem VBA

Předpokládejme, že klíčová slova, která potřebujete k vyhledání záznamu ve sloupci A, jak je uvedeno níže, proveďte následující kroky k vyplnění výsledků vyhledávání Google těchto klíčových slov do odpovídajících sloupců s kódem VBA.

1. zmáčkni Další + F11 klávesy pro otevření Microsoft Visual Basic pro aplikace okno.

2. V Microsoft Visual Basic pro aplikace okno, klikněte prosím Vložit > Modul. Poté zkopírujte a vložte kód VBA do okna kódu.

Kód VBA: vyplnění výsledků vyhledávání Google do listu

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 = "" & 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"
        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
    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:

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, 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!
officetab bottom
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
I have not been able to pull anything from google either. I followed instructions exactly.
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
This code requires you to buy and download Kutools to make this code run successfully. Has anyone found an option without the Kutools add-in?
This comment was minimized by the moderator on the site
Hi Mat,There is no relationship between Kutools and the code. You don't need to download or buy Kutools, just apply the code step-by-step as mentioned in the post.
This comment was minimized by the moderator on the site
Hi Crystal

Sorry but I got an "Object Variable not set" on line 24
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations