我得到下面的代碼。我想了解在Excel VBA中的錯誤處理。瞭解Excel VBA錯誤處理
Sub LoopErrorHandling()
Dim ws As Worksheet
Dim c As Range
On Error GoTo LoopErrorHandling_Err
Set ws = ThisWorkbook.Worksheets(1)
ws.Range("C1:C5").ClearContents
For Each c In ws.Range("A1:A5").Cells
c.Offset(0, 2).Value = c.Value/c.Offset(0, 1).Value
Next c
LoopErrorHandling_Exit:
On Error Resume Next
Set ws = Nothing
On Error GoTo 0
Exit Sub
LoopErrorHandling_Err:
MsgBox Err.Description
Resume Next
Resume LoopErrorHandling_Exit
End Sub
我想了解以上代碼中的以下內容。
- 應行
Set ws = Nothing
來後或行LoopErrorHandling_Exit:
之前到來。 - 不應該行
LoopErrorHandling_Err:
就夠了,是LoopErrorHandling_Exit:
必要的。 LoopErrorHandling_Exit:
上面的代碼和 是什麼工作,只有在發生錯誤時才觸發。- 以上代碼是否涵蓋了所有錯誤處理需要在excel vba或缺少東西。
'設置WS = Nothing'真的不應該在那裏的all..'LoopErrorHandling_Exit'是neccessary在這個片段中(*因爲沒有'退出Sub'標籤*之前的任何地方)。'LoopErrorHandling_Exit:'是當'LoopErrorHandling_Exit'被觸發或者當正常代碼執行到達每個循環之後代碼將跳轉到的'label',因爲沒有'Exit Sub' – 2014-10-20 09:41:01
你應該看到[THIS ARTICLE](http://www.cpearson.com/excel/errorhandling.htm) – 2014-10-20 09:45:53
@ vba4all:對不起,沒有看到您的評論 – 2014-10-20 09:52:51