在嵌套循环期间使msgbox显示状态?

时间:2016-08-21 23:55:08

标签: vba excel-vba macros excel

我在我的宏中遇到了一个错误,当它在输入数据列表中运行时,它突然停止但仍然以开发模式运行。

For LngRow = 2 To Wksht.Range("A" & Wksht.Rows.Count).End(xlUp).Row
        If Wksht.Cells(LngRow, 1) <> "" Then
            IE.Navigate Wksht.Cells(LngRow, 1)

            'This loops waits for IE to be ready
            Do Until (IE.Document.ReadyState = "complete") And (Not IE.busy)
                DoEvents
            Loop

            'grabs address
            For Each c In Array("vk_sh vk_bk", "_Xbe")
                dd = ""
                dd = IE.Document.getElementsByClassName(c)(0).innerText
                If Len(dd) > 0 Then
                    Wksht.Cells(LngRow, 3) = dd
                    Exit For

            MsgBox "Working on", , dd 'doesn't work

                End If
            Next

            'grabs business name
            For Each b In Array("kno-ecr-pt kno-fb-ctx _hdf")
                bb = ""
                bb = IE.Document.getElementsByClassName(b)(0).innerText
                If Len(bb) > 0 Then
                Wksht.Cells(LngRow, 9) = bb
                Exit For
              End If
           Next

           'Grabs phone number
           For Each a In Array("_Xbe _ZWk kno-fv")
                aa = ""
                aa = IE.Document.getElementsByClassName(a)(0).innerText
                If Len(bb) > 0 Then
                Wksht.Cells(LngRow, 10) = aa
                Exit For
              End If
           Next

        End If
    Next

它做的是通过IE页面的地址并从中获取信息,每个for循环用于包含在一个更大的循环(嵌套)中的不同信息。

我试图做的是显示一个msgbox说&#34;工作(dd)&#34;,所以我可以看到它当时处理的是什么地址所以我可以看到它是什么类型的地址坚持下去。然后当然要让它消失。我通过将&#34; MsgBox&#34; Workin放在&#34;,,dd&#34;但那并没有奏效。我不知道在嵌套循环的上下文中将它放在何处。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

if条件后尝试使用msgbox。

         For Each c In Array("vk_sh vk_bk", "_Xbe")
            dd = ""
            dd = IE.Document.getElementsByClassName(c)(0).innerText
            If Len(dd) > 0 Then

               MsgBox "Working on", , dd 'doesn't work

                Wksht.Cells(LngRow, 3) = dd
                Exit For

            End If
        Next
相关问题