Help on this bit of code

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
805
Office Version
2016
Platform
Windows
I found this bit of code and would like to use it with some changes, currently it is not working for me, possible because it is set for FIREFOX and not IE. I am having trouble changing this as I am limited in VBA

This might be the issue
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
Dim link As Object
On Error Resume Next

sq = Cells(1).CurrentRegion.Resize(, 3)

For r = 2 To UBound(sq)

With CreateObject("MSXML2.serverXMLHTTP")
.Open "GET", "https://www.google.co.in/search?q=" & sq(r, 1) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000), 0
.setRequestHeader "Content-Type", "text/xml"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
.send
c00 = .ResponseText
End With

With CreateObject("htmlfile")
.body.innerHTML = c00
Set link = .getelementbyid("rso").getelementsbytagname("H3")(0).getelementsbytagname("a")(0)
End With

str_text = ""
str_text = Replace(Replace(link.innerHTML, "", ""), "", "")
sq(r, 2) = str_text
sq(r, 3) = link.href

Next

Cells(1).CurrentRegion.Resize(, 3) = sq
MsgBox "done"

Original link to code https://www.mrexcel.com/forum/excel-questions/748275-pulling-google-search-result-into-excel.html
Code is not mine, so I have put in as a quote
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Watch MrExcel Video

Forum statistics

Threads
1,099,751
Messages
5,470,568
Members
406,707
Latest member
drkjz

This Week's Hot Topics

Top