+ Reply to Thread
Results 1 to 6 of 6

Excel 2010 timing issues using Dir

  1. #1
    Registered User
    Join Date
    03-05-2012
    Location
    Lichfield, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Excel 2010 timing issues using Dir

    Hi, I have been experiencing timing issues using vba to process 6 CSV files in a folder. Basically, Excel misses files which are definitely in the folder.

    I have been able to get more files picked up by inserting Application.Wait statements, but even then the results are not always consistent. I have also had the same problem with using the Kill command - some files get deleted and some don't. Innserting a Wait seems to sove the problem, but I don't think this is other than a clumsy 'patch'.

    I have tried inserting DoEvents, but that makes no difference at all.

    Code snippet:

    Please Login or Register  to view this content.
    Sometimes it gets all 6 files, sometimes it just gets two or three. Really infuriating! Is this an Excel 2010 bug?
    Last edited by davesexcel; 03-05-2012 at 08:09 AM.

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Excel 2010 timing issues using Dir

    I can't say I've noticed any problems around using Dir. Are you sure the csv files all exist at the point where you start running the script? |They aren't being generated on the fly as it were?

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Excel 2010 timing issues using Dir

    Does it make a difference if you don't call your variable 'FileName', which is a reserved word?

  4. #4
    Registered User
    Join Date
    03-05-2012
    Location
    Lichfield, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel 2010 timing issues using Dir

    Thank you, Dave for the information about tags. I only joined today, so please take that into account!

    As regards FileName being a reserved word, a good suggestion, but changing it to MyFileName makes no difference. When I ran the program just now, it picked up just two files out of 6.

    Before this code, the program runs ftp.exe via a shell command and I found I had to insert a Wait of 2 seconds after that for this code to pick up the folder. So that might have something to do with it.

    Interestingly, inserting MsgBox commands to view each filename as it is found resolves the problem. I think this allows whatever process is hanging around to finish. But this program has to run with no intervention!

    I haven't got an older version of Excel any more, but this program seemed to work OK before I upgraded to 2010.

    Maybe something using DoEvents might help, but inserting it in the loop shows no difference.

  5. #5
    Registered User
    Join Date
    03-05-2012
    Location
    Lichfield, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel 2010 timing issues using Dir

    FireFly2012 - I think you have something there. Because some of these files are being downloaded via ftp, so maybe sometimes they haven't finished downloading. I need a way of checking when the downloads have finished.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Excel 2010 timing issues using Dir

    If you shell out to ftp then that will run in parallel with Excel, which would explain the problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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