注册 登录
编程论坛 VB6论坛

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

shenlong2006 发布于 2012-04-05 21:30, 409 次点击
我把红色部分的代码删除后,按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. '网址
  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
2 回复
#2
shenlong20062012-04-05 21:31
只有本站会员才能查看附件,请 登录
#3
苦寒2012-04-08 10:07
当条件“Val(.Document.All.tags("table")(1).Rows(0).Cells(0).innertext) = (p - 1) * 50 + 1”成立时,继续执行后续的操作;否则执行DoEvents,向系统递交控制权。否则程序就像死机了一样。

1