VBA处理错误

时间:2016-04-06 04:08:48

标签: vba

我想在IF条件下处理VBA中的错误对于我的以下代码,问题是当我写 On error resume Next 时它处理错误但继续下一个语句只是条件, 但我想跳到下一个循环

我的代码: -

On Error GoTo 0
On Error Resume Next
For intRow = 2 To intLastRow

  If selenium.getText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[5]") = DOS Then

    clmn = selenium.getText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[2]")
    selenium.findElementByLinkText(clmn).Click
    FileNo = FileNo + 1
    Worksheets("Input").Cells(intRow, 9).Value = FileNo

  End If

Next intRow

1 个答案:

答案 0 :(得分:1)

你可以告诉它在错误时跳转到制造商:

On Error GoTo errFound
For intRow = 2 To intLastRow
    If selenium.GetText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[5]") = DOS Then
        clmn = selenium.GetText("//form[@id='searchForm']/div[3]/div/div/table/tbody/tr[1]/td[2]")
        selenium.findElementByLinkText(clmn).Click
        FileNo = FileNo + 1
        Worksheets("Input").Cells(intRow, 9).Value = FileNo
    End If
errFound:
Next intRow

但是,我会在那里放一些if语句来尝试处理错误,而不是仅仅跳过它们,