首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

请教以下这段代码中红色标注部分有什么作用呢

2012-04-14 
请问以下这段代码中红色标注部分有什么作用呢?我把红色部分的代码删除后,按F8单步运行能得到正确结果,但是

请问以下这段代码中红色标注部分有什么作用呢?
我把红色部分的代码删除后,按F8单步运行能得到正确结果,但是直接点运行时却只能得到重复的数据,很疑惑,高手帮忙解释一下吧!
Sub a()
Dim ie1 As Object, dmt As Object, r As Object, i As Long, j As Long, n As Long, p As Long

'Load UserForm1
'UserForm1.Show 0
On Error Resume Next

[a1].CurrentRegion.Offset(1).Clear
Cells.NumberFormat = "@"
Set ie1 = UserForm1.WebBrowser1

With ie1
  .Navigate "http://stock.jrj.com.cn/report/yjyg.shtml" '网址
  Do Until .ReadyState = 4 And InStr(.Document.body.innertext, "行情 资讯 股吧") > 0
  DoEvents
  Loop
  Set dmt = .Document
End With

Set r = dmt.All.tags("table")(1).Rows
For i = 0 To r.Length - 1
  For j = 0 To r(i).Cells.Length - 1
  Cells(i + 2, j + 1) = r(i).Cells(j).innertext
  Next
Next
Set dmt = Nothing
Set r = Nothing

For p = 2 To 23
  With ie1
  .Navigate "javascript:myNiceTable.goPage(" & p & ");"
Do Until Val(.Document.All.tags("table")(1).Rows(0).Cells(0).innertext) = (p - 1) * 50 + 1
DoEvents
Loop 
 Set dmt = .Document
  End With

  Set r = dmt.All.tags("table")(1).Rows
  n = [a65536].End(3).Row + 1
  For i = 0 To r.Length - 1
  For j = 0 To r(i).Cells.Length - 1
  Cells(i + n, j + 1) = r(i).Cells(j).innertext
  Next
  Next
  Set dmt = Nothing
  Set r = Nothing

Next

Set ie1 = Nothing

[a1].CurrentRegion.Columns.AutoFit

MsgBox "ok!"

End Sub


[解决办法]
等待页面加载到能查找到关键字符串

热点排行