请给出下面excel vba的完整解释,要一一对应到excel的实际功能上去。是一个提取多个网页数据的代码
SubTest()DimiAsInteger,pAsInteger,rowsAsLongDimarr()AsString,tmp()AsStringOnErrorResu...
Sub Test()
Dim i As Integer, p As Integer, rows As Long
Dim arr() As String, tmp() As String
On Error Resume Next
[a1:a10] = Split("代码,名称,最新,涨跌,涨跌幅,前收,开盘,最高,最低,成交量,成交额,换手率,前一周涨跌,前一月涨跌,总股本,流通股本", ",")
For p = 1 To 22
With CreateObject("Msxml2.XMLHTTP")
.Open "get", "http://quote.cfi.cn/quotelist.aspx?sortfd=%E4%BB%A3%E7%A0%81&marketid=&hy=§ypeid=1&sortway=asc&stockcode=&page=" & p & "&mystock=", False
.send
tmp() = Split(Split(Split(Replace(.responsetext, "<nobr>", ""), "流通股本</a></td></tr>")(1), "</tr></table>1")(0), "<td>")
End With
ReDim arr(UBound(tmp) \ 16, 15)
For i = 1 To UBound(tmp)
arr((i - 1) \ 16, (i - 1) Mod 16) = Split(Filter(Split(tmp(i), ">"), "</")(0), "</")(0)
Next
rows = [a65536].End(xlUp).Offset(1, 0).Row
Application.Goto "R" & rows & "c1"
Cells(rows, 1).Resize(UBound(arr) + 1, 16) = arr
Next
[a1:a10].Columns.AutoFit
MsgBox "Ok"
End Sub 展开
Dim i As Integer, p As Integer, rows As Long
Dim arr() As String, tmp() As String
On Error Resume Next
[a1:a10] = Split("代码,名称,最新,涨跌,涨跌幅,前收,开盘,最高,最低,成交量,成交额,换手率,前一周涨跌,前一月涨跌,总股本,流通股本", ",")
For p = 1 To 22
With CreateObject("Msxml2.XMLHTTP")
.Open "get", "http://quote.cfi.cn/quotelist.aspx?sortfd=%E4%BB%A3%E7%A0%81&marketid=&hy=§ypeid=1&sortway=asc&stockcode=&page=" & p & "&mystock=", False
.send
tmp() = Split(Split(Split(Replace(.responsetext, "<nobr>", ""), "流通股本</a></td></tr>")(1), "</tr></table>1")(0), "<td>")
End With
ReDim arr(UBound(tmp) \ 16, 15)
For i = 1 To UBound(tmp)
arr((i - 1) \ 16, (i - 1) Mod 16) = Split(Filter(Split(tmp(i), ">"), "</")(0), "</")(0)
Next
rows = [a65536].End(xlUp).Offset(1, 0).Row
Application.Goto "R" & rows & "c1"
Cells(rows, 1).Resize(UBound(arr) + 1, 16) = arr
Next
[a1:a10].Columns.AutoFit
MsgBox "Ok"
End Sub 展开
1个回答
展开全部
Sub Test() '子程序 Test()
Dim i As Integer, p As Integer, rows As Long '定义变量 i 为 整型值,p 为 整型值,行数 为 长整型值
Dim arr() As String, tmp() As String '定义变量 arr() 为 字符串,tmp() 为 字符串
On Error Resume Next '当错误 转到 下一个
[a1:a10] = Split("代码,名称,最新,涨跌,涨跌幅,前收,开盘,最高,最低,成交量,成交额,换手率,前一周涨跌,前一月涨跌,总股本,流通股本", ",")
For p = 1 To 22 '设定变量范围为p=1到22
With CreateObject("Msxml2.XMLHTTP") '工作于<创建工程>("Msxml2.XMLHTTP")
.Open "get", "http://quote.cfi.cn/quotelist.aspx?sortfd=%E4%BB%A3%E7%A0%81&marketid=&hy=§ypeid=1&sortway=asc&stockcode=&page=" & p & "&mystock=", False
'<With对象>的打开文件 get
.send '<With对象>的send
tmp() = Split(Split(Split(Replace(.responsetext, "<nobr>", ""), "流通股本</a></td></tr>")(1), "</tr></table>1")(0), "<td>")
'tmp()=<分割字符串>(<分割字符串>(<分割字符串>(<替换字符串>(<With对象>的responsetext,"<nobr>",""),"流通股本</a></td></tr>")(1),"</tr></table>1")(0),"<td>")
End With 'With语句结束
ReDim arr(UBound(tmp) \ 16, 15) '重定义变量arr(<数组上限>(tmp)\16,15)
For i = 1 To UBound(tmp) '设定变量范围为i=1到<数组上限>(tmp)
arr((i - 1) \ 16, (i - 1) Mod 16) = Split(Filter(Split(tmp(i), ">"), "</")(0), "</")(0) 'arr((i-1)\16,(i-1)Mod16)=<分割字符串>(<按条件选并返回数组>(<分割字符串>(tmp(i),">"),"</")(0),"</")(0)
Next '下一个
rows = [a65536].End(xlUp).Offset(1, 0).Row '行数= [a65536]的<末端>(方向向上 )的<偏移>(1,0 )的行标
Application.Goto "R" & rows & "c1" ' 应用程序的 跳至 "R" & 行数 & "c1"
Cells(rows, 1).Resize(UBound(arr) + 1, 16) = arr '<单元格>坐标(行数,1 )的<重调大小>(<数组上限>(arr)+1,16)=arr
Next '下一个
[a1:a10].Columns.AutoFit '[a1 :a10]的 列标的自动调整
MsgBox "Ok" '<消息框>:"Ok"
End Sub '子程序结束
Dim i As Integer, p As Integer, rows As Long '定义变量 i 为 整型值,p 为 整型值,行数 为 长整型值
Dim arr() As String, tmp() As String '定义变量 arr() 为 字符串,tmp() 为 字符串
On Error Resume Next '当错误 转到 下一个
[a1:a10] = Split("代码,名称,最新,涨跌,涨跌幅,前收,开盘,最高,最低,成交量,成交额,换手率,前一周涨跌,前一月涨跌,总股本,流通股本", ",")
For p = 1 To 22 '设定变量范围为p=1到22
With CreateObject("Msxml2.XMLHTTP") '工作于<创建工程>("Msxml2.XMLHTTP")
.Open "get", "http://quote.cfi.cn/quotelist.aspx?sortfd=%E4%BB%A3%E7%A0%81&marketid=&hy=§ypeid=1&sortway=asc&stockcode=&page=" & p & "&mystock=", False
'<With对象>的打开文件 get
.send '<With对象>的send
tmp() = Split(Split(Split(Replace(.responsetext, "<nobr>", ""), "流通股本</a></td></tr>")(1), "</tr></table>1")(0), "<td>")
'tmp()=<分割字符串>(<分割字符串>(<分割字符串>(<替换字符串>(<With对象>的responsetext,"<nobr>",""),"流通股本</a></td></tr>")(1),"</tr></table>1")(0),"<td>")
End With 'With语句结束
ReDim arr(UBound(tmp) \ 16, 15) '重定义变量arr(<数组上限>(tmp)\16,15)
For i = 1 To UBound(tmp) '设定变量范围为i=1到<数组上限>(tmp)
arr((i - 1) \ 16, (i - 1) Mod 16) = Split(Filter(Split(tmp(i), ">"), "</")(0), "</")(0) 'arr((i-1)\16,(i-1)Mod16)=<分割字符串>(<按条件选并返回数组>(<分割字符串>(tmp(i),">"),"</")(0),"</")(0)
Next '下一个
rows = [a65536].End(xlUp).Offset(1, 0).Row '行数= [a65536]的<末端>(方向向上 )的<偏移>(1,0 )的行标
Application.Goto "R" & rows & "c1" ' 应用程序的 跳至 "R" & 行数 & "c1"
Cells(rows, 1).Resize(UBound(arr) + 1, 16) = arr '<单元格>坐标(行数,1 )的<重调大小>(<数组上限>(arr)+1,16)=arr
Next '下一个
[a1:a10].Columns.AutoFit '[a1 :a10]的 列标的自动调整
MsgBox "Ok" '<消息框>:"Ok"
End Sub '子程序结束
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询