K
KR
I've done a decent amount of low-level VBA coding, but I haven't done
anything at all with error handling (yet).
I have a loop that trys to open 5 different files from a target directory.
If the file is found, it will open the file and parse the data into arrays.
However, if the file is not found, I anticipate an error occuring when it
reaches:
Open MyLongFileName(n) For Input As #1
If it errors out, I want it to skip forward past the code that deals with
the file contents, and just start the next loop and try the next file.
My non-trained brain automatically assumes I have to set a boolean on
whether or not the file was found, using the error handler to set the value
completely separately ... but...
is there a way to set up the loop so that it all flows in-line? Basically to
just skip a bunch of code if an error occurs, within the loop. For example:
For EachFile = 1 to 5
On Error Go To NoFileFound 'for error handling
Open MyLongFileName(EachFile) For Input As #1
'do my stuff'
Close #1
NoFileFound: 'error handler
just continues to the next file loop
Next
Thanks for any advice/suggestions,
Keith
anything at all with error handling (yet).
I have a loop that trys to open 5 different files from a target directory.
If the file is found, it will open the file and parse the data into arrays.
However, if the file is not found, I anticipate an error occuring when it
reaches:
Open MyLongFileName(n) For Input As #1
If it errors out, I want it to skip forward past the code that deals with
the file contents, and just start the next loop and try the next file.
My non-trained brain automatically assumes I have to set a boolean on
whether or not the file was found, using the error handler to set the value
completely separately ... but...
is there a way to set up the loop so that it all flows in-line? Basically to
just skip a bunch of code if an error occurs, within the loop. For example:
For EachFile = 1 to 5
On Error Go To NoFileFound 'for error handling
Open MyLongFileName(EachFile) For Input As #1
'do my stuff'
Close #1
NoFileFound: 'error handler
just continues to the next file loop
Next
Thanks for any advice/suggestions,
Keith
