I'm at a loss on what is probably a simple error handling routine problem.
I am opening several text based files in one folder, running some text manipulation commands on them, and then saving them as Word 97 docs in another folder.
The file names are numeric and sequential, but not all of them exist (e.g. 5.txt, 7.txt, 8.txt, 12.txt, etc.). I am trying to get the macro I have written to go to the next file number if it cannot find a given file number. This is what I have so far:
------------------------------
Sub
On Error GoTo File_Error
For intFileName = 1 to 999
'Word then opens the old file
Documents.Open FileName:= stFileName & ".txt" - etc.
'Word then performs several clean-up procedures in the file
'Word then saves the file as intFileName & ".doc"
File_Error:
Next intFileName
Exit Sub
----------------------------------
My difficulty is with the way my error handling routine handles the Documents.Open command. The sub will try 1, fail - but not generate an error, then 2 , then give me a run-time error on 2.
I believe the error handling routine is working the first time, but after that it stops.
What I need is for the Documents.Open command to keep trying numbers until it reaches one that exists. I think it may have something to do with the fact that the error handling routine is still active after it processes the first error, but I have experimented with the Resume GoTo command and various other things with no luck.
Any help would be greatly appreciated.
I am opening several text based files in one folder, running some text manipulation commands on them, and then saving them as Word 97 docs in another folder.
The file names are numeric and sequential, but not all of them exist (e.g. 5.txt, 7.txt, 8.txt, 12.txt, etc.). I am trying to get the macro I have written to go to the next file number if it cannot find a given file number. This is what I have so far:
------------------------------
Sub
On Error GoTo File_Error
For intFileName = 1 to 999
'Word then opens the old file
Documents.Open FileName:= stFileName & ".txt" - etc.
'Word then performs several clean-up procedures in the file
'Word then saves the file as intFileName & ".doc"
File_Error:
Next intFileName
Exit Sub
----------------------------------
My difficulty is with the way my error handling routine handles the Documents.Open command. The sub will try 1, fail - but not generate an error, then 2 , then give me a run-time error on 2.
I believe the error handling routine is working the first time, but after that it stops.
What I need is for the Documents.Open command to keep trying numbers until it reaches one that exists. I think it may have something to do with the fact that the error handling routine is still active after it processes the first error, but I have experimented with the Resume GoTo command and various other things with no luck.
Any help would be greatly appreciated.