![]() |
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! |
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! |
All times are GMT +1. The time now is 06:02 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com