+ Reply to Thread
Results 1 to 11 of 11

sorting through the folder using macro

  1. #1
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    sorting through the folder using macro

    Can anyone please help me with a macro code that can:

    go through the folder with path (D:\user\desktop\foldername) and find files with name that contains "xxx_dataspecs.xls" in its name. and once it finds that name, it needs to go through my macro code "architecture" and once done with the code, find another file to run again. It needs to do this processuntil it runs out of files with that name in that folder....


    Please please please help me!!!!

    Thank You in advance.
    sisi001
    Last edited by sisi001; 07-01-2011 at 11:54 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: sorting through the folder using macro

    Hello sisi001,

    Will the directory D:\user\desktop\foldername be static? What is foldername?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: sorting through the folder using macro

    Hi Leith,
    Thanks for such a quick reply. I am really new to this field. I did not understand what do you mean by static.
    The folder name is Model.

    I would really really appreciate if you can help me.

    Thank You

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: sorting through the folder using macro

    Hello sis001,

    Thanks for filling that piece of information. Static means the directory path will not change. This can happen on network drives. I write a macro for you test.

  5. #5
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: sorting through the folder using macro

    yes the directory path will not change. the code should run untill all the files with name that contains _dataspecs.xls in that folder "model" is done running my macro.

    Thank You Leith.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: sorting through the folder using macro

    Hello sisi001,

    You will need to add your macro to this one below the commented line.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: sorting through the folder using macro

    Thank You very much Leith. I will try this now.

    One more quick question though: The path I gave you was only a dummy path for which you wrote the line FilePath = Wsh.SpecialFolders("Desktop") & "\Model". What will I use if I have a path like this: X:\2011group\canoeing\Pictures\Model(foldername where I need to sort)???

    Thank again. Really appreciated.

  8. #8
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: sorting through the folder using macro

    It did not work. My FileName always stays " ", so it does not go inside the loop at all.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: sorting through the folder using macro

    Hello sisi001,

    This macro will use the other file path you posted.
    Please Login or Register  to view this content.

    Is the file name "xxx_dataspecs.xls" where XXX = a number?

  10. #10
    Registered User
    Join Date
    06-20-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: sorting through the folder using macro

    yes Leith. It worked. But I am facing a very weird problem. Looks like I might be missing something.

    Inside my folder I have various files with name, Model1_dataspecs, Model2_dataspecs, Model_dataspecs. The code you gave be does the job of sorting through the files with dataspecs. But the values from each of the files are all messes up.

    I have:
    Please Login or Register  to view this content.

    the string variable a is returning wrong values. The A1 cell of Model1_dataspecs and Model2_dataspecs should have been empty and Model_dataspecs should have "name". But they are not returning what they are suppose to although they choose the correct FileName.

    Do you know what might be the problem?
    Last edited by Leith Ross; 07-01-2011 at 03:39 PM. Reason: Added Code Tags

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: sorting through the folder using macro

    Hello sisi001,

    I would say the problem is there is no other macro to retrieve the data is there? Let me know specifically what you need done using real data, file names, along with before and after examples.

+ 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