Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Error Handling and For-Next Loops

Thanks Bob- This works great! =)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling AA2e72E[_2_] Excel Programming 0 April 27th 04 04:06 PM
Error handling V. Roe Excel Programming 2 February 27th 04 08:04 PM
Error Handling Todd Excel Programming 1 February 13th 04 11:29 PM
Error handling Tim C Excel Programming 1 October 7th 03 10:00 PM
Error handling John Pierce Excel Programming 3 October 3rd 03 12:17 PM


All times are GMT +1. The time now is 01:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"