现在A股不止2000只股票了吧,网址改成http://quote.tool.hexun.com/hqzx/quote.aspx?type=2&market=0&sorttype=3&updown=up&page=1&count=3000吧
然后优化了下代码,可能这样快些吧。
- Option Explicit
- Sub test()
- Dim tmp() As String, i As Integer, arr() As String, xmlhttp As Object
-
- Sheets("快速行情").Select
- Sheets("快速行情").UsedRange.Clear
- Sheets("快速行情").Range("a1:M1") = Split("代码,名称,最新价,涨跌幅,昨收,今开,最高,最低,成交量,成交额,换手,振幅,量比", ",")
-
- Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
- With xmlhttp
- .Open "get", "http://quote.tool.hexun.com/hqzx/quote.aspx?type=2&market=0&sorttype=3&updown=up&page=1&count=3000", False
- .send
- tmp = Split(Split(Split(Replace(Replace(Replace(.responsetext, "'", ""), vbCrLf, ""), "],[", ","), "[[")(1), "]]")(0), ",")
- End With
- ReDim arr(UBound(tmp) \ 13, 12)
- For i = 0 To UBound(tmp)
- arr(i \ 13, i Mod 13) = tmp(i)
- Next
- Sheets("快速行情").Range("a2").Resize(UBound(arr, 1) + 1, UBound(arr, 2) + 1) = arr
- Sheets("快速行情").Columns("a:M").AutoFit
-
- Erase tmp
- Erase arr
- Set xmlhttp = Nothing
-
- MsgBox "Ok"
- End Sub
复制代码 |