ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Trapping (https://www.excelbanter.com/excel-programming/286856-error-trapping.html)

neil

Error Trapping
 
Hi, I have a data table that has file path and name
information, I am running a loop across it which opens up
each path&filename, reads in some data from the file into
an array, then closes the file and dumps the contents of
the array into my spreadsheet. This all works fine but I
want to error trap if a user deletes on of the files, I
can use the on error statement, but the fileopen
statement is in the loop, and once I go out of the loop
to the error code I dont know how to get back to the
correct place in my original loop ?


Tom Ogilvy

Error Trapping
 
why not avoid the error - don't try to open a missing file

sPath = "C:\My Documents"
for each cell in Range("A1:A10")
sStr = sPath & "\" & Cell.Value
if dir(sStr) < "" then
' file exists, open it
end if
Next

--
Regards,
Tom Ogilvy

"Neil" wrote in message
...
Hi, I have a data table that has file path and name
information, I am running a loop across it which opens up
each path&filename, reads in some data from the file into
an array, then closes the file and dumps the contents of
the array into my spreadsheet. This all works fine but I
want to error trap if a user deletes on of the files, I
can use the on error statement, but the fileopen
statement is in the loop, and once I go out of the loop
to the error code I dont know how to get back to the
correct place in my original loop ?





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com