Help on this bit of code

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,066
Office Version
  1. 2016
Platform
  1. 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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top