• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy All the files from Folder And SubFolder to One

rumshar

Member
Hi All,
After doing lots of googling I have come here. I am looking for a VBA code which should copy all the files from Folder and Subfolder to one location. It shouldn't copy the folder but only the contents.
I got Ron's code but my requirement is slightly different.

Wish you happy weekend.
Rudra
 
Out of curiosity, why do you want to use VBA? :)

Anyway, in your googling did you come by this

http://stackoverflow.com/questions/20219362/excel-vba-to-list-files-in-folder-and-subfolder-with-path-to-txt-file
I believe this is a nice starting point :)

Code:
Sub ShowFolderList(folderspec)
Dim fs, f, f1, fc, s, sFldr 
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
ForEach f1 In fc 
    ShowFolderList f1 
Next
Set fc = f.Files 
ForEach f1 In fc 
    Debug.Print folderspec & f1.Name
    'Name folderspec & f1.Name as whateveryouwant & f1.Name
Next
EndSub
 
@iferror
Thanks for your reply, I want to use VBA because I don't want to get into each SubFolder and look for certain files and copy them to different location.Regarding code you mentioned, I am getting Error @ ShowFolderList f1.

With Regards
Rudra
 
Hi, rumshar!
If it's a one time only process, start Windows Explorer, go to main folder, type "*.*" in top right search box, make some coffee, select all files, and do whatever you want to do.
Regards!
 
@ sirJB7, Thanks for your reply.
*.* yeilded folders also, which I didn't want...is it a trick to April Fool me? I used wildcard "*" instead.
Unfortunately this is lunch time so can't make coffee either..I almost fooled my parent by coming to this world on 2nd April.
::::Rudra.
 
@rumshar
Hi!
You can always exclude folders sorting by name type. And no, here we "celebrate" April's fools day on December 28th, or I should say that there are people who "celebrate" the Innocents Day on April 1st instead on normal December 28th.
Regards!
 
Back
Top