+ Reply to Thread
Results 1 to 18 of 18

VBA Code to Move Individual Files from 1 Folder to a new Folder

  1. #1
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hi All

    New to the Forum so howdy everyone

    I have 6 individual folders each with up to 150 .jpg files, what I need to accomplish is to move the first file in each individual folder 1-6 into a new folder called 1 ie new folder 1 will then have 6 new files which were the first files in each folder, and then proceed to the second file in each folder and loop until done. I hope this makes sense and can be done in VBA.

    I would appreciate any help

    Thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    1) Is there some relationship between the file to be taken from each of the 6 folders? Names perhaps? Some worksheet listing their relationship?
    2) Can you list the full path to the 6 folders?
    3) Can you explain how the new folder should get its name? Related in some way to the names of the files being moved?
    4) What is the full path to where these new folders will reside?


    I'm saying this all sounds doable, but this requires surgical detail, so we need everything in your head about this before we can start to surmise an approach.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    This is easily done.
    I will create something for you.
    The Output folder will need to be called "Output"
    then six folders "Folder1" to "Folder6"
    All Seven folders will need to be in the same Folder.
    The macro will reside in the Same Folder as the Seven Folders detailed above.

    You have not specified but I assume you want the JPegs renumbered.

    I will number then thus. Loop No - Original Folder . JPG

    You should be able to modify the numbering system quite easily.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 11-08-2014 at 03:28 PM.

  4. #4
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hello mehmetcik,

    Thank you so much for your quick response - it is much appreciated

    Quick question i have placed the code in a new workbook in "this Workbook" module I am getting an error at set fsoFolder

    Runtime error 76 "path not found"

    Sorry i am a total newbie so I might be getting something totally wrong

    I have created a new folder on my Desktop and named the folders as you explained\

    Thank you in anticipation for your assistance

  5. #5
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hello JBeaucaire

    Thank you for your response and assistance in answer to your questions :
    1) Is there some relationship between the file to be taken from each of the 6 folders? Names perhaps? Some worksheet listing their relationship? - These files are all consecutively numbered .jpegs each folder containing the exact same amount of .jpegs upto 150 off in each
    2) Can you list the full path to the 6 folders? I can put the folders anywhere on the C:; drive
    3) Can you explain how the new folder should get its name? Related in some way to the names of the files being moved? Each new folder should be numbered 1 to 150 ie the same as the qty of jpegs
    4) What is the full path to where these new folders will reside? They can reside anywhere on c:

    I would like the jpegs to be renamed as they are moved for consistency ie, First jpeg in Original folder 1 to be named 1_1.jpeg First in Folder 2 to 2_1 etc thro to 6_1.jpeg all these 6 into Newfolder named 1

    I hope this makes sense

    Thanks again for the assistance

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    The workbook must be in the same folder as the 7 folders that I discussed

    So in that folder you will have 7 folders and one workbook

  7. #7
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hi - Thanks Yes I have them all in the same folder on my Desktop
    Attached Images Attached Images

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    try putting them in a folder on your desktop

    Ahhh your folder names are wrong. Folder1, Folder2, etc

    if you want spaces then you need to modify my code

    Get it working as I had it first.

  9. #9
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hi mehmetcik

    Thank you for your reply - as per the image above I have placed all the files in a folder on my desktop. I had previously overlooked your demo Output worksheet which i have now downloaded and also tried - I am still getting the same error ie it does not pickup the directory path is there a way to possibly hardcode this??

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Your Folder names are wrong. I specified Folder1 you have Folder 1

  11. #11
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Wow - my bad thanks that worked wonderfully all files moved into the output folder Thank You
    Now one last thing I need to put each set of 6 new files in the output folder in a folder named 1 through to x
    Thank yo that has saved me a huge amount of time and so simple

  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Are you asking for the code to be modified?

    If so what exactly do you need?

  13. #13
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Hi -Yes please I need the new files in output to be in their own folders
    ie Files 1-1 thro 1-6 into subfolder New1, files 2-1 thro 2-6 in subfolder New2 and so on... all in the Output folder ie I will then have x number of folders each with 6 files in them

    Thanks for your patience

  14. #14
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Ok try this code.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-07-2014
    Location
    Hoedspruit,South Africa
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    Thank you sir , that works perfectly

    Much appreciated

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  17. #17
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    This version gives you a counter at the bottom of excel.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-06-2014
    Posts
    9

    Re: VBA Code to Move Individual Files from 1 Folder to a new Folder

    i need a similar application

    move a list of file names listed in colmn A to a new folder

    Source folder contains around 50000 pics
    and list contain 1000 file names(123.*,4789.*).
    pls help me to make a code

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  3. Rename individual files within a folder
    By Smally in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2014, 10:16 AM
  4. [SOLVED] VBA Code to Move Excel files from one folder to another
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-04-2013, 12:33 PM
  5. Move Files from Folder to Folder
    By THE_RAMONES in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2006, 04:25 PM

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