View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Kilmer[_2_] Bob Kilmer[_2_] is offline
external usenet poster
 
Posts: 71
Default 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.