title: How to create a HTTP GET in Excel VBA
body: <p>Good afternoon all,</p>
  
  <p>I'm working on a project for work where I need to get vehicle values based on registration number and mileage and feed these into an Excel spreadsheet.</p>
  
  <p>The registration number and mileage is stored in the spreadsheet but I'm stuck on where to start for getting started.</p>
  
  <p>I created a rough VBA application last weekend which looked as follows</p>
  
  <p>The registration number and mileage is stored in the spreadsheet but I'm stuck on where to start for getting started.</p>
  
  <p>I created a rough VBA application last weekend which looked as follows:</p>
  
  <p>Sub GetHTMLDocument()</p>
  
  <pre><code>Dim IE As New SHDocVw.InternetExplorer
  Dim HTMLDoc As MSHTML.HTMLDocument
  Dim Email As MSHTML.IHTMLElement
  Dim Password As MSHTML.IHTMLElement
  Dim LoginButton As MSHTML.IHTMLElement
  Dim REG As MSHTML.IHTMLElement
  Dim Mileage As MSHTML.IHTMLElement
  Dim CAPGo As MSHTML.IHTMLElement
  Dim objEvent
  Dim GetValue As MSHTML.IHTMLElement
  
  'Show IE for testing purposes
  IE.Visible = True
  'Navigate to web page
  IE.Navigate "https://valuationanywhere.cap.co.uk/LoginPage?ReturnUrl=%2f%3f__hstc%3d208265677.8bb2d3e6c872f15cd37070c17648ee29.1549763639794.1549763639794.1549763639794.1%26__hssc%3d208265677.1.1549763639794%26__hsfp%3d959865525&amp;__hstc=208265677.8bb2d3e6c872f15cd37070c17648ee29.1549763639794.1549763639794.1549763639794.1&amp;__hssc=208265677.1.1549763639794&amp;__hsfp=959865525"
  
  'Loop an empty loop until done
  Do While IE.ReadyState &lt;&gt; READYSTATE_COMPLETE
  Loop
  
  Set HTMLDoc = IE.Document
  
  'inputs email address
  Set Email = HTMLDoc.getElementById("inputLoginEmail")
  Email.Value = "email"
  'inputs password
  Set Password = HTMLDoc.getElementById("inputLoginPassword")
  Password.Value = "password"
  'Clicks login button
  Set LoginButton = HTMLDoc.getElementById("btnLogin")
  LoginButton.Click
  
  'Wait 3 seconds for page to load
  Application.Wait (Now + TimeValue("0:00:03"))
  
  Set objEvent = IE.Document.createEvent("HTMLEvents")
  
  'Input REG into text box
  Set REG = HTMLDoc.getElementById("vrm")
  REG.Value = "reg"
  'Input mileage into text box
  Set Mileage = HTMLDoc.getElementById("mileage")
  Mileage.Value = "181000"
  
  'Fakes data entry as no focus is given to the text box
  objEvent.initEvent "change", False, True
  REG.dispatchEvent objEvent
  Mileage.dispatchEvent objEvent
  
  'Clicks Go button
  Set tags = IE.Document.getElementsByTagName("button")
  For Each tagx In tags
  If tagx.innerText = "Go" Then
      tagx.Click
      Exit For
  End If
  Next
  
  'Wait 3 seconds for popup to load
  Application.Wait (Now + TimeValue("0:00:03"))
  
  Set tags = IE.Document.getElementsByTagName("button")
  For Each tagx In tags
  If tagx.innerText = "Create NEW Valuation" Then
      tagx.Click
      Exit For
  End If
  Next
  </code></pre>
  
  <p>This would navigate to the page, log me in and search for valuation. However we will eventually have a database of hundreds of cars we want to get valuations on and our CAP service has some plugins here - <a href="https://soap.cap.co.uk/vrm/capvrm.asmx?op=VRMValuation" rel="nofollow noreferrer">https://soap.cap.co.uk/vrm/capvrm.asmx?op=VRMValuation</a></p>
  
  <p>Is there any way I can have VBA pick a reg and mileage from a sheet, and pull back the value?</p>
  
  <p>I'm not expecting anyone to write the entire thing I would love to learn from this. But can anyone point me in the right direction?</p>
  
  <p>Kindest regards,
  Craig</p>