+ Reply to Thread
Results 1 to 5 of 5

GetFolder Method of FileSystemObject Fails On Second Pass

  1. #1
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    GetFolder Method of FileSystemObject Fails On Second Pass

    Hi all,

    Using Excel 2007

    I use the GetFolder() method of the FileSystemObject to consolidate some files
    Please Login or Register  to view this content.
    I destroy the Folder and File objects when the first For Each..Next loop completes
    Please Login or Register  to view this content.
    Now I want to use the GetFolder() method again with a different directory
    Please Login or Register  to view this content.
    However, on the second loop the files from the 1st folder are accessed?
    I have reviewed the variables

    Please Login or Register  to view this content.
    Any other idea(s) what to check on?

    thx
    w
    Kind regards,
    w

    http://dataprose.org

  2. #2
    Registered User
    Join Date
    07-30-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: GetFolder Method of FileSystemObject Fails On Second Pass

    Of course always the obvious.. typos, etc.

    If that is all good, I would recommend stepping through the macro (with F8) and making sure the lines of code setting Set objFolder = Nothing, etc. are actually getting run.

    If it is running like you say then you wouldn't be having this problem so I suspect the issue is with how the code is running and that it isn't doing what you expect/think it is.


    EDIT:
    Also, another possibility I just thought of is that the variable (strMapTemplates) may not be what you expect when it is accessed. When the Set fileObj = strMapTemplates line is run, you should see what that variable actually is at that point in time.

  3. #3
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: GetFolder Method of FileSystemObject Fails On Second Pass

    Thanks biocidej,

    I tried adding a second folder objFolder2
    Now when I run I get an error on the first GetFolder

    Error message states "FileName.xls could not be found"
    If that is true, how does it pickup the filename in th first place?
    The filename it says it cannot find is correct.
    I opened the folder and I can see the file

    I set a break point immediately after
    Please Login or Register  to view this content.
    I hover on the variable strDirectory (returns "C:\dir1\" as expected)
    I hover on the variable objFolder (returns "C:\dir1") not sure why the "\" is dropped?

    I moved the breakpoint down a bit
    Please Login or Register  to view this content.
    When I hover on objFile here it only shows the name of the file "MapFile.xls"

    thx
    w

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: GetFolder Method of FileSystemObject Fails On Second Pass

    See if you can work with this

    Please Login or Register  to view this content.
    Last edited by mike7952; 11-13-2012 at 06:12 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: GetFolder Method of FileSystemObject Fails On Second Pass

    Thanks Mike,

    I ran your code which tought me to use objFile.Path instead of objFile.Name
    Works great!

    thx
    w

+ 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