+ Reply to Thread
Results 1 to 9 of 9

File Not Found in correct directory, but able to read file name

  1. #1
    Registered User
    Join Date
    08-27-2008
    Location
    United States
    Posts
    45

    File Not Found in correct directory, but able to read file name

    Hello,

    I have a peculiar error happening. I have a userform that opens a particular directory to read in all file names, then puts them into a list. After this happens it allows the user to delete them, but for some reason I get a "file not found" error on the following code --


    Please Login or Register  to view this content.
    The directory never changes or anything, and the program can read the file names in perfectly fine, but for some reason, when I try to open the file for input it errors out on me...
    Please Login or Register  to view this content.
    I don't understand what I'm doing wrong, unless I'm missing something blatantly obvious. The msgbox DOES return an existing filename in that folder, but it then cannot open it for input...

    I'm stumped, and would greatly appreciate help

    Thanks in advance,
    GoogleBot

  2. #2
    Registered User
    Join Date
    08-27-2008
    Location
    United States
    Posts
    45
    Can someone please change the title to "File Not Found When In correct Directory And Able To Read File Name" please?

    I forgot to make a good title :-\
    Last edited by Paul; 09-26-2008 at 08:49 PM. Reason: Edited title per user's request. Thanks!

  3. #3
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    Do either of these work?
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hi

    Your code works fine for me in test. What is the filename that is being returned Dir? Please post it exactly as it appears in your message box.

    Richard

  5. #5
    Registered User
    Join Date
    08-27-2008
    Location
    United States
    Posts
    45
    ...

    after the weekend, with no code changes, it suddenly is working?

    ...

    RichardSchollar, the name was the exact file name -- "adsdf.txt" in this case, and that was what the msgbox showed...


    How could I get excel to duplicate this error? I don't know what I would have changed over the weekend :-\ Is there any way network connections (being on a wireless vs ethernet cable) would cause something like this? It seems that because it accesses the C: drive that shouldn't matter

  6. #6
    Registered User
    Join Date
    08-27-2008
    Location
    United States
    Posts
    45
    I cannot edit my above message, but the error is now back


    edit -- after changing the command to "append" and then running it (working), I changed it back to "input" and it functions correctly :-\

    So I have absolutely no idea what's going on.
    Last edited by googlebot; 09-29-2008 at 11:23 AM.

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    Only thing I can think of is this:

    Note:

    The ChDir lets you change the current directory on the current drive. If you need to change drives, try using the ChDrive statement first.
    Perhaps somehow the 'active' drive letter isn't always right? But then it's still a mystery to me as to how the msgbox works.

    Thought: I wonder if Excel does an 'autosave' operation if that would change the active drive, or folder?

    To be honest to make sure I have everything right I've never used ChDir and assumed I'm in the correct directory / drive. I'd tend to do this:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-27-2008
    Location
    United States
    Posts
    45
    Phil,

    I believe that is exactly what I was trying to do. I was opening files from other drives, and that must change Excel's active drive.

    I also think that the reason it was able to open the files and read the names in was because it specifies that folder and drive, whereas with my "Input" statement, it did not (I assumed it would keep that same drive/directory).

    After experimenting with that for a while I have decided that including the entire path name is DEFINITELY the way to go when opening files where multiple drives might be in use

    Thank you very much, I would have fought this for years before realizing it XD

  9. #9
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    Of course! You are correct about the msgbox. Looking back at the code that makes sense. Seems that little piece of 'debugging assistance' was actually a red-herring as it wasn't doing the 'EXACT' same thing as your actual code.
    Still, glad we sorted it out, and yes, I truly believe fully qualified paths are the solution to many problems

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Unable to read file
    By KA_Analyst in forum Excel General
    Replies: 2
    Last Post: 10-06-2008, 10:11 AM
  2. Error: Unable to read file
    By whitepaw in forum Excel General
    Replies: 1
    Last Post: 08-31-2008, 07:07 AM
  3. macro to import text file
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2008, 09:08 AM
  4. how to let excel really read my file as it is
    By will27 in forum Excel General
    Replies: 3
    Last Post: 10-11-2007, 12:55 PM
  5. Creating a stamp of who opened a file in directory
    By AmyTaylor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2006, 11:23 PM

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