I am trying to automate the search using VBA Excel and I recently started to get the error which I can not figure out how to fix... compile error:
Script searching this website
for values from column B for example serial field value: 98-0001
I'd appreciate any help on error and further testing the script...thank you
Script searching this website
Military Database
scramble.nl
VBA Code:
Sub Scramble()
Dim cel As Range, ms As Worksheet, dom As HTMLDocument, loopRange As Range
Const SEARCH_URL As String = "https://www.scramble.nl/index.php?option=com_mildb&view=search"
' USAF --------------------------------------------------------------------------------------------------------------------------
Set ms = ThisWorkbook.Worksheets("Scramble")
Set dom = New HTMLDocument
Set loopRange = ms.Range("B2:B" & ms.Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(2)
Application.ScreenUpdating = False
With CreateObject("winhttp.winhttprequest.5.1")
For Each cel In loopRange
.Open "POST", SEARCH_URL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send "Itemid=60&af=usaf&serial=" & cel & "&sbm=Search&code=&searchtype=&unit=&cn="
dom.body.innerHTML = .responseText
Dim recordFields As Object
Set recordFields = dom.querySelectorAll(".rowBord td")
If recordFields.Length > 0 Then
With cel
.Offset(, -1) = recordFields.Item(2).innerText 'Type
.Offset(, 2) = recordFields.Item(1).innerText 'Code
.Offset(, 3) = recordFields.Item(4).innerText 'Unit
.Offset(, 10) = recordFields.Item(3).innerText 'C/N
.Offset(, 11) = recordFields.Item(5).innerText 'Status
.Offset(, 7) = "USAF"
End With
End If
Next
End With
End Sub
I'd appreciate any help on error and further testing the script...thank you