(Solved) – excel vba to printscreen website to specific cells [closed]

  • by
(solved)-–-excel-vba-to-printscreen-website-to-specific-cells-[closed]
Private Sub CommandButton1_Click()

'Private Sub TAXandMOTcheck()
'Sub TAXandMOTcheck()

'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser

'''''''''''''''''''''''''''''''''''''''''''
'OPEN INTERNET

'initiating a new instance of Internet Explorer and assigning it to objIE
    Set objIE = New InternetExplorer

'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

'''''''''''''''''''''''''''''''''''''''''''
'OPEN TAX/ MOT PAGE

'navigate IE to this web page (a pretty neat search engine really)
    objIE.navigate "https://vehicleenquiry.service.gov.uk/?_ga=2.227083613.1149091750.1575026484-3812246.1573638547"
    '"https://vehicleenquiry.service.gov.uk/"

'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

On Error GoTo TIMERS1

TIMERS1:
'wait seconds
    Application.Wait Now   TimeValue("00:00:01")

'''''''''''''''''''''''''''''''''''''''''''

'enter details in to pages

'in the search box put cell
    objIE.Document.getElementById("wizard_vehicle_enquiry_capture_vrn_vrn").Value = _
    Sheets("TAX, MOT, MID").Range("C5").Value

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop


On Error GoTo TIMERS2

TIMERS2:
'wait seconds
    Application.Wait Now   TimeValue("00:00:01")


'''''''''''''''''''''''''''''''''''''''''''''''''''''

'click the 'Continue' button
    objIE.Document.getElementsByClassName("govuk-button")(0).Click

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

On Error GoTo TIMERS3

TIMERS3:
'wait seconds
    Application.Wait Now   TimeValue("00:00:05")

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'click the 'Yes' button
    objIE.Document.getElementById("yes-vehicle-confirm").Click

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop


'''''''''''''''''''''''''''''''''''''''''''''''''''''

'click the 'Continue' button
    objIE.Document.getElementsByClassName("govuk-button")(0).Click

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

On Error GoTo TIMERS4

TIMERS4:
'wait seconds
    Application.Wait Now   TimeValue("00:00:01")


'''''''''''''''''''''''''''''''''''''''''''''''''''''

'MOT
On Error Resume Next
'MOT EXPIRY DATE:
    MotExpiryDate = objIE.Document.getElementsByClassName("div govuk-!-font-size-24 govuk-panel__body")(0).getElementsByTagName("strong")(1).innerText
    MotExpiryDate = Split(MotExpiryDate, vbNewLine)(0)

'add mot date to sheet
    Range("C6").Value = MotExpiryDate

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'TAX
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
    TaxExpiryDate = objIE.Document.getElementsByClassName("govuk-panel__body govuk-!-font-size-24")(0).getElementsByTagName("strong")(1).innerText
    TaxExpiryDate = Split(TaxExpiryDate, vbNewLine)(0)

'add tax date to sheet and note y as counter for looping
    Range("C7").Value = TaxExpiryDate

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'MAKE
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
   MAKE = objIE.Document.getElementsByClassName("govuk-summary-list__value")(0).innerText

'add make to sheet
   Range("C8").Value = MAKE

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'REGISTERED DATE
On Error Resume Next
   REGISTERED = objIE.Document.getElementsByClassName("govuk-summary-list__value")(1).innerText

'add YearOfMake date to sheet
    Range("C9").Value = REGISTERED

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'MANUFACTURER YEAR
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
    MANUFACTURERYEAR = objIE.Document.getElementsByClassName("govuk-summary-list__value")(2).innerText

'add make to sheet
   Range("C10").Value = MANUFACTURERYEAR

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'ENGINE SIZE
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
    ENGINESIZE = objIE.Document.getElementsByClassName("govuk-summary-list__value")(3).innerText

'add make to sheet
   Range("C11").Value = ENGINESIZE

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'C02
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      C02 = objIE.Document.getElementsByClassName("govuk-summary-list__value")(4).innerText

'add make to sheet
   Range("C12").Value = C02


'''''''''''''''''''''''''''''''''''''''''''''''''''''

'FUEL TYPE
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      FUEL = objIE.Document.getElementsByClassName("govuk-summary-list__value")(5).innerText

'add make to sheet
   Range("C13").Value = FUEL

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'EURO STATUS
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      EURO = objIE.Document.getElementsByClassName("govuk-summary-list__value")(6).innerText

'add make to sheet
   Range("C14").Value = EURO

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'REAL DRIVING EMISSIONS
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      EMISSIONS = objIE.Document.getElementsByClassName("govuk-summary-list__value")(7).innerText

'add make to sheet
   Range("C15").Value = EMISSIONS

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'EXPORT MARKER
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      Export = objIE.Document.getElementsByClassName("govuk-summary-list__value")(8).innerText

'add make to sheet
   Range("C16").Value = Export

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'VEHICLE STATUS
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      Status = objIE.Document.getElementsByClassName("govuk-summary-list__value")(9).innerText

'add make to sheet
   Range("C17").Value = Status

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'COLOUR
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      COLOUR = objIE.Document.getElementsByClassName("govuk-summary-list__value")(10).innerText

'add make to sheet
   Range("C18").Value = COLOUR

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'VEHICLE TYPE
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      VEHICLETYPE = objIE.Document.getElementsByClassName("govuk-summary-list__value")(11).innerText

'add make to sheet
   Range("C19").Value = VEHICLETYPE

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'WHEEL PLAN
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      WHEELPLAN = objIE.Document.getElementsByClassName("govuk-summary-list__value")(12).innerText

'add make to sheet
   Range("C20").Value = WHEELPLAN

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'WEIGHT
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      Weight = objIE.Document.getElementsByClassName("govuk-summary-list__value")(13).innerText

'add make to sheet
   Range("C21").Value = Weight

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'DATE OF LAST V5 CHANGE
On Error Resume Next
'IN TWO LINES FOR BETTER CODE READIBILITY:
      V5 = objIE.Document.getElementsByClassName("govuk-summary-list__value")(14).innerText

'add make to sheet
   Range("C22").Value = V5

'''''''''''''''''''''''''''''''''''''''''''''''''''''

On Error Resume Next
'Application.SendKeys "^%" & "PRTSC"

Application.SendKeys "(%{1068})"
DoEvents

Application.ScreenUpdating = False
      '  ActiveSheet.Paste <<< this works but i cant get it to past to certain cells/ group of cells
       Range("E4:L23").Paste '<<< trying this to paste the printscreen to the given cells but it doesnt work

'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''

'close the browser
    objIE.Quit

'exit our SearchBot subroutine and start new row for new website data
    End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *