2016-04-06 87 views
0

我要处理的假设条件VBA错误对于我下面的代码的问题是,当我写在错误恢复下一页它处理错误,但与下一条语句继续只为条件, 但我要跳到下一个for循环VBA来处理错误

我的代码: -

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

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

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语句来尝试处理错误,而不是仅仅跳过它们,