Help on this bit of code

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,661
Messages
6,120,792
Members
448,994
Latest member
rohitsomani

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