|
请参考
Dim xmlobject As Object
Dim strReturn As String
Dim strUrl As String
Dim intLen As Long
Dim intLenA As Long
Dim arry As Variant
On Error Resume Next '利用错误陷井
Set xmlobject = CreateObject("microsoft.xmlhttp")
r = Sheet1.[b65536].End(xlUp).Row
Debug.Print r
For i = 1 To r '5000 '遍历,相当于当前股票行数
strUrl = "http://hq.sinajs.cn/list=" & Cells(1 + i, 2) '起始股票代码单元格,格式要求前缀sz或sh
xmlobject.Open "GET", strUrl, False
xmlobject.send
If xmlobject.readystate = 4 Then
strReturn = xmlobject.responsetext
strReturn = Mid(strReturn, 22, Len(strReturn) - 24) '剔除无关数据
arry = Split(strReturn, ",") '按逗号分隔数据,放入数组arry
intLenA = UBound(arry) - LBound(arry) + 1 '数组长度,此处未使用,可结合For遍历arry
'获取目标数据
Cells(1 + i, 3) = arry(0) '0名称1今开2昨收3现价4最高5最低6买一价7卖一价8成交量9成交额10~29为五档信息30日期31时间
Cells(1 + i, 4) = Round((arry(3) - arry(2)) / arry(2), 4) * 100
Cells(1 + i, 5) = arry(3)
Cells(1 + i, 6) = arry(1)
Cells(1 + i, 7) = arry(2)
Cells(1 + i, 8) = arry(4)
Cells(1 + i, 9) = arry(5)
Cells(1 + i, 10) = arry(8) / 1000000
Cells(1 + i, 11) = arry(9) / 10000
End If
Next i
End Sub
|
|