+ Reply to Thread
Results 1 to 15 of 15

Excel Macro Code Request for List files and Move specified directory

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Excel Macro Code Request for List files and Move specified directory

    Dear all,

    Please find below is my request to create macro code:

    Step1: Browse Directory.
    Step2: List files in above selected directory.
    Step3: Create directory based on the file <Please do not use file extension and it contain same file name with different extension>
    Step4: Move files based on its named directory.

    Please help us to get this process solution.

    Please let me know if you have any clarifications in this regard.

    Thanks & Regards
    Attached Files Attached Files
    Last edited by ganeshinscribe; 03-19-2012 at 08:37 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    There's probably much better ways of doing this but it sounded interesting.
    1. Select a Folder and Click OK. The files in that Folder will be listed.
    2. Select one (1) file of the file name you want to move (ignore the file extension...all files with the file name selected will be moved). Click Open.
    3. Having selected one(1) file name, a new folder will be created with name of the file name selected in Step 2. This folder will be a sub folder of the Folder selected in Step 1
    4. All the files with the selected file name are then moved to the new folder.
    I don't have Excel 2003 but it should work in Excel 2002 and higher. I'd recommend you run the code on copies of your live file...just in case. Let me know of issues.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi John,

    Thank You very much to try and we have only MS office 2003 & higher (2007). While running this macro,



    Step 1: Correct.

    (Additional to Step1) = Write selected directory path in Cell "A5"

    Step 2: List files in Excel Sheet.

    Write file names in B5, B6....


    Step 3: <here we need to select one button to create directory>.
    Create directory based on the unique file name from B5, B6..... and it should be sub folder of which we selected Step 1

    Step 4: <Here we need to select one button to move files>
    After selecting this button, all the files move to its named folder.


    In above code, we did not found named folder and it was not moved.

    Please find below screen shot for your kind reference.






    First option is correct

    Please find below screen shot for your kind reference.

    Step 2.jpg

    Step 3.jpg

    Kindly review and let me know if you have any questions.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    Reading your last post, it appears to me that you want 2 Buttons. The first Button to populate the worksheet with relevant information and to create the Directory. The second Button to do the actual move. Is my understanding correct?

  5. #5
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    Yes John.

    Please help us to get this solution.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    Try the code in the attached. There are two Buttons:
    1. Show Me: populates the sheet with the relevant data...it does NOT create the new folder. It simply tells you what it'll be named.
    2. Move Me: creates the new folder and moves the files.
    If you wish, this line of code in Show_Me can be changed to direct the User to their start folder
    Please Login or Register  to view this content.
    I've un-merged the cells in Column D...VBA doesn't like merged cells. Let me know of issues.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    Thank You John !!!


    I got a error message while running. Please find attached screen shot for your kind reference.


    RunTime Error.JPG

    Kindly help us to resolve this solution.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    Well, you know, I now get the same error message. Seems, when I was cleaning up the code, I deleted a line that I shouldn't have...sorry about that. In Show_Me code, please insert this line
    Please Login or Register  to view this content.
    Let me know of issues.

  9. #9
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    Excellent John,

    It was working but folder creating only administrator instead of file name. Please help me to solve this code.

    Please see the picture for your kind reference.

    folder.JPG

    Thanks

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    In your screen shot I can't see what column A says. Make the column wider so I can see it.

  11. #11
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    John,

    I have updated entire folder path in attached image.

    Also, It will work with any directory or path selection from "show me" directory?

    folder1.JPG

    I want to run any directory instead of specified only "C:" is this possible?

    Thanks

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    I'd like to see your screen shot from Post #9 but with Column A widened so I can see what it says.

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    Never mind, I see what's happening. I'll need to look at it. I'll get back to you.

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro Code Request for List files and Move specified directory

    Hi ganeshinscribe
    Well, we'll try once again. I believe this issue is resolved
    but folder creating only administrator instead of file name
    Regarding this
    I want to run any directory instead of specified only "C:" is this possible
    You can go to any directory you wish (up the Tree or down the Tree). If you don't want to start in C:\ simply change this line of code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    In either case you can navigate up or down the Tree. Let me know of issues.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    02-07-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Excel Macro Code Request for List files and Move specified directory

    Thank You John.

    It was perfect !!!

+ 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