+ Reply to Thread
Results 1 to 9 of 9

Runtime error '53': File not found

  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Exclamation Runtime error '53': File not found

    Hello,

    This thread was born out of my frustration and exhaustion of trying to find out why my macro (which is supposed to loop through a series of text files) would not work. Even worse, it would work once and then stop working. The constant error message was Runtime error '53': File not found. Online searching for a quick fix, repairing my registry, re-installing Office, and trying the same file on multiple different computers did not resolve the issue. As a last ditch attempt, I tried something desperate... I saved my code in text file as unicode so that it would only save the letters, numbers, etc without anything else and opened a fresh new workbook and pasted it. All of a sudden, the problems went away. I tried this new file on multiple computers (all running Office 2007 under Windows XP) and it worked just fine.

    If I stopped here then it would be a happy ending, but unfortunately I ran the macro on several computers running Office 2007 running under Windows Vista, and sure enough the problem re-appeared: Runtime error '53': File not found.

    My question is: Has anyone had this problem with Vista before when trying to loop through text files, or any othe file type for that matter? I know the files are there because I see them and I can open them, and if I replace the loop with the file path or use Application.GetOpenFilename("Text Files,*.txt"), it works and so the macro can see and open the files, but it just can't do it with the loop.

    Any suggestions? (And sorry for the long post, but if I can help just one person to not to have to go through the misery that I went through, then it will have been worth it)

    abousetta

    P.S. attached is the new file that works under XP, but not vista and a text file that contains the needed material
    Attached Files Attached Files
    Last edited by abousetta; 04-30-2010 at 12:21 PM.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Runtime error '53': File not found

    See attached file, I hope it runs fine.
    I think your problem is due to use of dir () together open file, because when using dir () with the opening of a file dir () gives problems.

    Regards,
    Antonio
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Runtime error '53': File not found

    Hi antoka05,

    Thanks for taking the time to go over the code and providing your feedback. It is higly appreciated. This approach is new to me, but I'm new to vba

    So you have replaced the original code for looping through files by using the Dir function:

    Please Login or Register  to view this content.
    to this new code (which by the way works so far when the first code did not):

    Please Login or Register  to view this content.
    So far, this has circumvented the issues caused by Dir and I will definately test it for speed and accurracy on multiple operating systems.

    In general do you always use this method or only when Dir fails?

    Thanks again.

    abousetta

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Runtime error '53': File not found

    I prefer to use the file system object method because it is reliable and powerful.
    With file system object it's possible move or rename files and folders, read in one isctruction all a text file and assign it to a variable.

    Regards,
    Antonio

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Runtime error '53': File not found

    Thanks Antonio for sharing your experience. Good advice that I will remember to use in the future when looping through files (which I need to do frequently).

    Best wishes,

    abousetta

  6. #6
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Runtime error '53': File not found

    If you don't open files during dir() loop you can use dir() but I remember when open a file in a dir () loop it's like losing pointing to files and gives in error.

    Regards,
    Antonio

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Runtime error '53': File not found

    Hi Antonio,

    That's exactly what was happening to me. If I asked it to loop through the files and give me the names in message box... no problem. When I told it to then open the file... No, No, No... Error 53.

    Thanks again Antonio.

    Best wishes,

    abousetta

  8. #8
    Registered User
    Join Date
    09-12-2012
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Runtime error '53': File not found

    Dear Abosetta,

    I have also the similar problem while rename the pdf files in excel.
    Can you help in this regard
    thread as follows.

    http://www.excelforum.com/excel-prog...cel-macro.html

    Regards

    Prasanna.E

  9. #9
    Registered User
    Join Date
    08-19-2004
    Posts
    22

    Re: Runtime error '53': File not found

    Dear Abosetta and antoka05,
    I had the similar problem and that fixing Dir() thing helped me to fix me problem.
    Thank you very much both of you.
    Cheers
    Baha

    Best Regards,
    Baha

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1