Error Handling and For-Next Loops
Hi
I am in the (hopefully) last stage of finishing my File Scanner. However, I have run into some files where the Permission is denied (Err.Number=70). To get around this, I have set up an Error Handler. The main snippets of my program is shown below ----------------------------- Sub StoreFiles( On Error Goto ErrHandle .. For Each File in File .. SkipFile Next Fil .. Exit Su ErrHandler If Err.Number=70 The Resume SkipFil EndI End Sub( ----------------------------- However, doing this comes back with the error that the For Loop wasnt initialised (Error 92)€ How can I get around this Many thanks for your help SuperJas |
Error Handling and For-Next Loops
Use inline error handling: Wrap the call that raises the error in On Error
Resume Next and On Error Goto 0, On Error Resume Next <line(s) that raise(s) error On Error Goto 0 which just ignores the error regardless, or use something like this, which re-raises unexpected errors, but ignores expected ones. On Error Resume Next <line that raises error ErrNum = Err.Number If ErrNum < 0 Then If ErrNum < 70 Then Err.Raise ErrNum 'or Exit Sub, or,... End If End If Bob "SuperJas" wrote in message ... Hi, I am in the (hopefully) last stage of finishing my File Scanner. However, I have run into some files where the Permission is denied (Err.Number=70). To get around this, I have set up an Error Handler. The main snippets of my program is shown below: ------------------------------ Sub StoreFiles() On Error Goto ErrHandler ... For Each File in Files ... SkipFile: Next File ... Exit Sub ErrHandler: If Err.Number=70 Then Resume SkipFile EndIf End Sub() ------------------------------ However, doing this comes back with the error that the For Loop wasn't initialised (Error 92). How can I get around this? Many thanks for your help, SuperJas. |
Error Handling and For-Next Loops
Thanks Bob- This works great! =)
|
All times are GMT +1. The time now is 11:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com