Cum să populezi rezultatele căutării Google în foaia de lucru în Excel?
În unele cazuri, poate fi necesar să efectuați câteva căutări importante de cuvinte cheie în Google și să păstrați înregistrarea rezultatelor de căutare de sus într-o foaie de lucru care include titlul și hyperlinkul articolului. Acest articol oferă o metodă VBA pentru a ajuta la popularea rezultatelor căutării Google într-o foaie de lucru pe baza cuvintelor cheie date în celule.
Completați rezultatele căutării Google pe foaia de lucru cu cod VBA
Completați rezultatele căutării Google pe foaia de lucru cu cod VBA
Presupunând cuvintele cheie de care aveți nevoie pentru a căuta listarea în coloana A, așa cum este prezentată mai jos, vă rugăm să faceți următoarele pentru a completa rezultatele căutării Google ale acestor cuvinte cheie în coloanele corespunzătoare cu cod VBA.
1. apasă pe Alt + F11 tastele pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.
2. În Microsoft Visual Basic pentru aplicații fereastra, faceți clic pe Insera > Module. Apoi copiați și lipiți codul VBA în fereastra codului.
Cod VBA: populați rezultatele căutării Google în foaia de lucru
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:
- How to populate a combo box with specified data on Workbook open?
- How to auto populate other cells when selecting values in Excel drop down list?
- How to auto populate other cells when selecting values in Excel drop down list?
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-2021 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
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!
Sort comments by
#28233
This comment was minimized by the moderator on the site
Report
0
0
#28234
This comment was minimized by the moderator on the site
0
0
#29011
This comment was minimized by the moderator on the site
0
0
#30491
This comment was minimized by the moderator on the site
0
0
#30492
This comment was minimized by the moderator on the site
Report
0
0
#30493
This comment was minimized by the moderator on the site
0
0
There are no comments posted here yet