Hgreen1601
New Member
- Joined
- Jun 15, 2021
- Messages
- 18
- Office Version
- 2016
- Platform
- Windows
I have been trying to make a macro where I enter a license plate and it searches the gov.uk website (https://vehicleenquiry.service.gov.uk) and returns the cylinder capacity.
Relatively new to macro writing so any explanation would be appreciated, currently have numerous errors.
Relatively new to macro writing so any explanation would be appreciated, currently have numerous errors.
VBA Code:
Sub EngineSearch()
Dim Tool As Object
Dim Var As Variant
Dim element As Variant
Dim WrkBk As Workbook
Dim WrkSht As Worksheet
Set WrkBk = ThisWorkbook
Set WrkSht = WrkBk.ActiveSheet
For i = WrkSht.Range("E3").Value To WrkSht.Range("F3").Value
'Have put the cells of my data range within these values
Set Tool = CreateObject("InternetExplorer.Application")
Tool.navigate "[URL]https://vehicleenquiry.service.gov.uk/[/URL]"
Tool.Visible = False
Application.Wait (Now + TimeValue("0:00:01"))
Set frm = Tool.document.getelementbyid("wizard_vehicle_enquiry_capture_vrn_vrn")
frm.Value = WrkSht.Cells(i, 2).Value
Tool.document.getelementbyid("submit_vrn_button").Click
Application.Wait (Now + TimeValue("0:00:01"))
Tool.document.getelementbyid("yes-vehicle-confirm").Click
Tool.document.getelementbyid("capture_confirm_button").Click
Application.Wait (Now + TimeValue("0:00:01"))
Set HtmlType = ie.document.getelementbyid("cylinder_capacity")
WrkSht.Range("C" & i) = Right(HtmlType.innerText, 7)
Tool.Quit
Next i
Exit Sub