I have a range of cells formatted as an Excel Table with headers of "VRM" and "MOT Expiry". There is a list of registration numbers in the VRM column and presently the MOT Expiry column is empty.
I have the below code which checks registration numbers listed in the 'VRM' column using internet explorer for the MOT expiry date. The check is working fine but I have two issues:
1. I'm struggling to get the returned date in to the 'MOT Expiry' column on the same row as the checked VRM. Depending which option I use (both are in the below code), I either replace the registration number in the original column or put the returned date in every row on the 'MOT Expiry' column.
2. The date being returned with the .innerText command is preceded by "Expires: ", so looks like "Expires: 01/01/2022", is there a way to remove this so I just get the date?
Thanks in advance.
I have the below code which checks registration numbers listed in the 'VRM' column using internet explorer for the MOT expiry date. The check is working fine but I have two issues:
1. I'm struggling to get the returned date in to the 'MOT Expiry' column on the same row as the checked VRM. Depending which option I use (both are in the below code), I either replace the registration number in the original column or put the returned date in every row on the 'MOT Expiry' column.
2. The date being returned with the .innerText command is preceded by "Expires: ", so looks like "Expires: 01/01/2022", is there a way to remove this so I just get the date?
VBA Code:
Sub MOT_Check3()
Dim rngColMOT As Range
Dim rngColVRM As Range
Dim cl As Range
Dim ie As InternetExplorer
Dim sURL As String
Dim Expiry As Variant
sURL = "https://www.checkcardetails.co.uk/"
Set ie = New InternetExplorer
Set rngColVRM = Sheet1.Range("Table1[VRM]")
Set rngColMOT = Sheet1.Range("Table1[MOT Expiry]")
For Each cl In rngColVRM
With ie
.AddressBar = 0
.StatusBar = 0
.Toolbar = 0
.Visible = True
.Navigate sURL
Do Until Not .Busy And .ReadyState = 4
DoEvents
Loop
'Puts VRM in VRM field on website
Debug.Print cl.Value
.Document.all("reg_num").Value = cl.Value
Application.Wait Now + TimeSerial(0, 0, 2)
End With
Do Until Not ie.Busy
DoEvents
Loop
'Press 'Submit' button
ie.Document.all("submit-button").Click
Do Until Not ie.Busy
DoEvents
Loop
Expiry = ie.Document.all("mot-expiry-text").innerText
' cl.Value = Expiry 'This replaces VRM with MOT expiry date
rngColMOT.Value = Expiry 'This fills 'MOT Expiry' column with MOT expiry date
Next cl
End Sub
Thanks in advance.