Sub ExtractDataFromHtml()
Dim objExcel As Worksheet
Dim objIE As SHDocVw.InternetExplorer
Dim varTables, varTable
Dim varRows, varRow
Dim varCells, varCell
Dim lngRow As Integer
Dim lngColumn As Integer
Dim strBuffer
Dim VINS
Dim URL As String
Dim count As Integer
Dim RowIndex As Integer
Dim check As String
Dim FromDate As String
Dim ToDate As String
Dim FromTime As String
Dim Totime As String
Dim Hall As String
Dim Vin As String
Dim UrlPart1, UrlPart2 As String
Dim VinCol, CheckPtCol, TypeCol, CarrierCol, TimeCol, StatusCol As Integer
VinCol = 1 'first column: VIN
CheckPtCol = 2 'second column: check point
TypeCol = 3 'third column: Type (E70, F25...)
CarrierCol = 4 'fourth column: carrier number
TimeCol = 5 'fifth column: time stamp
StatusCol = 6 'sixth column: status
Set objExcel = ActiveWindow.ActiveSheet
FromDate = Date
ToDate = DateAdd("m", 3, Date)
FromTime = "00:00:10"
Totime = "23:59:10"
Hall = 10
Vin = "LL71528"
UrlPart1 = "
UrlPart2 = "&baaSubmit"
'objExcel.Cells(27, 3).Value = myfunction(5, 9)
count = objExcel.UsedRange.Rows.count + 1 'Number of VINS in current sheet
RowIndex = 2 'Index for while loop
Set objIE = CreateObject("InternetExplorer.Application") 'Internet Explorer Object
While RowIndex < count 'start
If Not IsEmpty(objExcel.Cells(RowIndex, 1)) Then
objExcel.Cells(RowIndex, TimeCol).NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
Vin = Trim(objExcel.Cells(RowIndex, 1).Value)
URL = UrlPart1 & "fromDate=" & FromDate & "&fromTime=" & FromTime & "&toDate=" & ToDate & "&toTime=" & Totime & "&carrier=N/A&carrier_end=N/A&hall=" & Hall & "&vin=" & Vin & UrlPart2
'URL = BuildUrl(FromDate, FromTime, ToDate, Totime, Hall, Vin)
'open url and wait until page is loaded
objIE.Navigate URL
While objIE.Busy
Application.Wait (10)
Wend
While objIE.Document.ReadyState <> "complete"
Application.Wait (10)
Wend
'look for all tables
Set varTables = objIE.Document.All.tags("table")
For Each varTable In varTables
check = varTable.Rows(0).Cells(0).innertext
If check = "VIN " Then
Set varCells = varTable.Rows(1).Cells 'get cells of the second row only
lngColumn = 1 'This will be the output column
For Each varCell In varCells
objExcel.Cells(RowIndex, lngColumn).Value = varCell.innertext
lngColumn = lngColumn + 1
Next
End If
Next
End If
RowIndex = RowIndex + 1 'increment counter
Wend
objIE.Quit
End Sub