title: VBA to automate google search
body: <p>I am using below mentioned VBA Script to automate google search(Required results only in English), but getting error 91,Plz suggest solution.Other requirement is I require non personalized google search result</p>
  
  <pre><code>Sub XMLHTTP()
  
      Dim url As String, lastRow As Long
      Dim XMLHTTP As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object
      Dim start_time As Date
      Dim end_time As Date
  
      lastRow = Range("A" &amp; Rows.Count).End(xlUp).Row
  
      Dim cookie As String
      Dim result_cookie As String
  
      start_time = Time
      Debug.Print "start_time:" &amp; start_time
  
      For i = 2 To lastRow
  
          url = "https://www.google.com/webhp?hl=en&amp;as_q=&amp;as_epq=&amp;as_oq=&amp;as_eq=&amp;as_nlo=&amp;as_nhi=&amp;lr=lang_en&amp;cr=countryUS&amp;as_qdr=all&amp;as_sitesearch=&amp;as_occt=any&amp;safe=images&amp;as_filetype=&amp;as_rights=" &amp; Cells(i, 1) &amp; "&amp;rnd=" &amp; 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 html = CreateObject("htmlfile")
          html.body.innerHTML = XMLHTTP.ResponseText
          Set objResultDiv = html.getelementbyid("rso")
          Set objH3 = objResultDiv.getelementsbytagname("H3")(0)
          Set link = objH3.getelementsbytagname("a")(0)
  
  
          str_text = Replace(link.innerHTML, "&lt;EM&gt;", "")
          str_text = Replace(str_text, "&lt;/EM&gt;", "")
  
          Cells(i, 2) = str_text
          Cells(i, 3) = link.href
          DoEvents
      Next
  
      end_time = Time
      Debug.Print "end_time:" &amp; end_time
  
      Debug.Print "done" &amp; "Time taken : " &amp; DateDiff("n", start_time, end_time)
      MsgBox "done" &amp; "Time taken : " &amp; DateDiff("n", start_time, end_time)
  End Sub
  </code></pre>