|
前辈你好,我想请教下在打开网页发生错误时要如何使用On Error语句,比如以下代码里的"http://www.cffex.com.cn/fzjy/tjsj/pztj/pzrtj/2014/index.xml"网页无法打开超过3秒钟我就要终止本次采集。要如何加入代码可以达到我的要求。
Sub Main()
Dim arrEM(1 To 4), arrEMname
Dim arrData(1000, 1 To 4)
Dim i As Long, j As Long
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://www.cffex.com.cn/fzjy/tjsj/pztj/pzrtj/2014/index.xml", False
.send
arrEMname = Array(, "productid", "tradingday", "volume", "openinterest")
With .responseXML
For i = 1 To 4
Set arrEM(i) = .getElementsByTagName(arrEMname(i))
Next
For i = 0 To arrEM(1).Length - 1
For j = 1 To 4
arrData(i, j) = arrEM(j)(i).Text
Next
Next
End With
End With
Cells.Clear
Range("a1:d1").Value = Array("品种", "日期", "总成交量", "总持仓量")
Range("a2").Resize(i, 4).Value = arrData
End Sub
复制代码 |
|