+ Reply to Thread
Results 1 to 14 of 14

Files move to a subfolder

  1. #1
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Files move to a subfolder

    Hi,

    I want move all the xls files from a folder (C:\Test) to a subfolder (C:\Test\2009), but not move "ThisWorkbook".

    I try this
    Please Login or Register  to view this content.
    but isnt working at all.

    Thanks in advance for any help
    Last edited by Jokacave; 04-22-2010 at 02:07 PM.

  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: Files move to a subfolder

    Hello Jokacave,

    Here is the amended macro. This is much easier to do with VBA than the FSO.
    Please Login or Register  to view this content.
    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
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    Hi Leith Ross,

    Thank you for trying to help me...
    I try ur code but don.t move any file to the subfolder.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Files move to a subfolder

    Try this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    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: Files move to a subfolder

    Hello Jokacave,

    Did it create the the new directory? Have you saved the workbook with the macro?

  6. #6
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    Yes, to both questions.

  7. #7
    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: Files move to a subfolder

    Hello Jokacave,

    The Name ... As statement should have moved the file to the new directory. What version of Excel are you using?

  8. #8
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    The 2003 version

  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: Files move to a subfolder

    Hello Jokacave,

    Sorry, I didn't catch this earlier. The to folder in the Name As statement is misspelled. It should be this...
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    I try ur code but move every file and I want move all the files but not the files where is the code. And i need create the subfolder before run the code but i think i can turn around that "problem".

  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: Files move to a subfolder

    Hello Jokacave,

    I ran the macro and it skips moving the workbook the macro is in. Did you want to do something different?

  12. #12
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    Leith Ross,

    Great. Now, works perfectly.
    Thk u 4 ur help.

  13. #13
    Forum Contributor
    Join Date
    12-19-2006
    Posts
    113

    Re: Files move to a subfolder

    Hi shg,

    Thk u 4 ur help. Ur code have a few froblems 4 what I want - I posted at 01:44 AM.
    Thk u anyway

  14. #14
    Registered User
    Join Date
    04-06-2010
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Files move to a subfolder

    Hi, theres a few problems you face with the existing code...

    1) the folder already exists when you try and make it
    2) user enters an invalid folder name
    3) code doesnt actually loop through files etc.

    Heres 2 pieces of code - insert both into the VBE and then run the MoveExcelFiles sub

    This function returns true if the folder name is acceptable to Windows or false if its not
    Please Login or Register  to view this content.
    This code copies over Excel files to your new subfolder
    Please Login or Register  to view this content.
    regards,
    Graham

+ 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