Public Sub hello(ByVal region As String, ByVal targetTB As String)
Dim arr(1 To 2000, 1 To 25), r As Long, str As String
Dim mats, mapID, mat, dArr, ub As Long, col As Long
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "GET", "http://priceboard.fpts.com.vn/" & region & "/data.ashx?s=quote&l=" & targetTB, False
.send
str = .ResponseText
End With
mapID = Array(1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, _
16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, 25)
ub = UBound(mapID) + 1
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\[""?(\d{1,2})""?,""?([^\]""]+)""?"
dArr = Split(str, "}")
For r = 0 To UBound(dArr)
Set mats = .Execute(dArr(r))
For Each mat In mats
col = mat.submatches(0)
If col < ub Then
If mapID(col) > 0 Then
arr(r + 1, mapID(col)) = mat.submatches(1)
End If
End If
Next
Next
End With
Sheet1.Range("A5").Resize(UBound(arr), UBound(arr, 2)).Value = arr
End Sub