Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Error trapping

I would like to know if there is a way to catch a specific error. I allow
users to conditionally select files by checking boxs on a userform. If the
file doens't exist I would like to process the program as if the box was not
checked. The problem I'm having is not knowing which file is missing so I
don't know what part of the program to skip. For example:

Run-tim error '1004':

'filesname.CSV' COULD NOT BE FOUND. CHECK THE SPELLING OF THE FILE NAME, AND
VERIFY THAT THE FILE LOCATION IS CORRECT.

If filename.csv is missing I would like to skip the code that processes the
data in filename.csv. I could handle it with a bunch of error routines but I
would rather find out if I can extract the name of the missing file from the
error.

Thanks in advance for the help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Error trapping

The Dir function is a rather powerful way of trawling for files and
directories. Maybe you could use Dir to check whether or not the file exists
before you try to access it, and thus your code wouldn't have to throw
exceptions at all?

IMHO, exceptions should not be used as a mechanism to handle standard
conditions that you can easily anticipate and address before they actually
cause you any trouble. One typical example of such a condition is when the
file you're trying to access is missing -- instead of trying to catch the
error I think you should try to prevent it...

Anyhow, if you want to handle only certain types of errors you can always
check what's stored in the Err object (Number and Description). Then you let
your error handler take care of the errors you want to manage, and just
re-throw the rest.

Cheers,
/MP

"hshayh0rn" wrote:

I would like to know if there is a way to catch a specific error. I allow
users to conditionally select files by checking boxs on a userform. If the
file doens't exist I would like to process the program as if the box was not
checked. The problem I'm having is not knowing which file is missing so I
don't know what part of the program to skip. For example:

Run-tim error '1004':

'filesname.CSV' COULD NOT BE FOUND. CHECK THE SPELLING OF THE FILE NAME, AND
VERIFY THAT THE FILE LOCATION IS CORRECT.

If filename.csv is missing I would like to skip the code that processes the
data in filename.csv. I could handle it with a bunch of error routines but I
would rather find out if I can extract the name of the missing file from the
error.

Thanks in advance for the help!

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 Trapping gazza67[_2_] Excel Discussion (Misc queries) 2 September 6th 07 06:11 PM
error trapping JohnE Excel Programming 2 April 27th 06 03:50 PM
Error Trapping Rafi Excel Programming 3 February 14th 06 11:42 PM
Error Trapping Andrew Excel Programming 1 April 5th 05 07:23 AM
Error Trapping Neil Excel Programming 1 January 5th 04 04:38 PM


All times are GMT +1. The time now is 01:32 AM.

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

About Us

"It's about Microsoft Excel"