Excel的强大就不用说了,用的人都知道。
用Excel获取行情的实时数据可以做很多的事情,套利、行情分析……,并且直观,可定制性高。
如何用Excel获取行情数据呢?
需要用到VBA编程
例如需要调用hs300版块300只股票所有的价格
首先列出需要调用的300只股票数据
之后在模块中完成代码如下
Sub 按钮1_Click()
Dim
xmlobject As Object
Dim
strReturn As String
Dim strUrl
As String
Dim intLen
As Long
Dim intLenA
As Long
Dim temp As
Variant
Set
xmlobject = CreateObject("microsoft.xmlhttp")
For i = 1 To
300
strUrl =
"http://hq.sinajs.cn/list="
& Cells(2 + i, 2) & Cells(2 + i,
3)
xmlobject.Open "GET", strUrl, False
xmlobject.send
If
xmlobject.readystate = 4 Then
strReturn = xmlobject.responsetext
intLen = Len(strReturn) - 25
strReturn = Mid(strReturn, 22, intLen)
temp = Split(strReturn, ",")
intLenA = UBound(temp) - LBound(temp) + 1
For j = 1 To intLenA
Cells(2 + i, 3 + j) = temp(j - 1)
Next j
End If
Next i
End Sub
加载中,请稍候......