I have a function that renames and copies files from one directory to another. Here is a sample of the code
My problem is that I am still getting Permission Denied errors within the loop when the following occurs:
Attempting to copy a file, xyz.pdf, to a directory that already contains a file named xyz.pdf and the file to be overwritten is open.
This program is supposed to be running 24 hours a day and it always crashes with a "Permission Denied" error instead of just going to the next fille. For the life of me I cannot figure out why it doesn't just jump to errNext_File. Any help would be greatly appreciated.
Thanks!!
Code:
'Set sNextFile to a PDF File in source_directory
sNextFile = Dir$(SOURCE_DIRECTORY + "*.PDF")
On Error GoTo errNext_File
Loop_Start:
'Loop Until all Files in source_directory are read
While sNextFile <> ""
.
.
.
'Goto Next File
sNextFile = Dir$
Wend
Exit Sub
errNext_File:
'Goto Next File
sNextFile = Dir$
'MsgBox (Error)
GoTo Loop_Start
End Sub
My problem is that I am still getting Permission Denied errors within the loop when the following occurs:
Attempting to copy a file, xyz.pdf, to a directory that already contains a file named xyz.pdf and the file to be overwritten is open.
This program is supposed to be running 24 hours a day and it always crashes with a "Permission Denied" error instead of just going to the next fille. For the life of me I cannot figure out why it doesn't just jump to errNext_File. Any help would be greatly appreciated.
Thanks!!