title: Return first image link from google search in excel using vba
body: <p>It is possible to modify this code to search for large images and to return the link of the first image. I tryed to modify the google link with the google image link but it doesent work</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><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/search?q=" &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>
  </div>
  </div>
  </p>