Good afternoon all,
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.
The registration number and mileage is stored in the spreadsheet but I'm stuck on where to start for getting started.
I created a rough VBA application last weekend which looked as follows
The registration number and mileage is stored in the spreadsheet but I'm stuck on where to start for getting started.
I created a rough VBA application last weekend which looked as follows:
Sub GetHTMLDocument()
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&__hstc=208265677.8bb2d3e6c872f15cd37070c17648ee29.1549763639794.1549763639794.1549763639794.1&__hssc=208265677.1.1549763639794&__hsfp=959865525"
'Loop an empty loop until done
Do While IE.ReadyState <> 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
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 - https://soap.cap.co.uk/vrm/capvrm.asmx?op=VRMValuation
Is there any way I can have VBA pick a reg and mileage from a sheet, and pull back the value?
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?
Kindest regards, Craig