I am attempting to run vba code to perform a number of operations on a folder of excel files. This code had been written by someone else no longer with my company, but the VBA script worked when last run. Now, when I attempt to run it, I keep getting run time error 52 (“Bad file name or number”). Any suggestions?
The code is much longer, but the error (per the debugger) highlights as such:
Print #intFreeFile, _
" *XXXXXXXXX * * * Error in code 'main_ProcessBringFwd' " & Err & ": " & _
The problem is probably this one told by the error message.
Open the code and look for commands trying to read or save files. They are probably using an invalid path.
Somewhere in your code you might have something like this:
Open file_name For Output As #intFreeFile
Debug your code and check if the value in “file_name” (it may be other var name) is a valid path and also a valid file name.
If the file is a network file then the program may not be able to find the file if there is a temporary network failure, I have ran into this issue several times.
The fix to this type of error is to check that the drive / folder exists before opening the file.
I found out that when I got this error message, it was because I was trying to use a
: in the name of the file. As soon as I removed it, the macro ran perfectly. I think there may be a conflict with the code when it comes to special characters.