How often do you have to do this? does it HAVE to be done in VBA? It's fairly simple to do it manually:
In Windows File Manager (explorer), simply search the top-level folder for * then, select all of the files and drag them to the "master" folder. If you still want it to be done with VBA, it's fairly simple too. try: Option Explicit Global fso, Fldr_Dest '------------------------------------------------------ Sub Move_Files() Dim fldr, File, stat Set fso = CreateObject("Scripting.FileSystemObject") Fldr_Dest = "C:\temp3\" fldr = "C:\temp2" stat = Get_SubFolder(fldr) MsgBox "Finished" End Sub '------------------------------------------------------ Function Get_SubFolder(fldrname) Dim stat, fldr, File, sfldr 'Dim FldrSplit, TempFldr 'Dim fc, fscr 'Dim flc If (fso.folderexists(fldrname)) Then Set fldr = fso.getfolder(fldrname) For Each File In fldr.Files stat = Move_File(fldrname, File.Path) Next File For Each sfldr In fldr.subfolders stat = Get_SubFolder(sfldr.Path) Next sfldr End If End Function '------------------------------------------------------ Function Move_File(fldrname, FullName) If (Right(fldrname, 1) <> "\") Then fldrname = fldrname & "\" Debug.Print FullName fso.copyfile FullName, Fldr_Dest End Function '------------------------------------------------------ hope this helps, Paul ----- Original Message ---- > From: Mari <mariappan...@gmail.com> > To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> > Sent: Tue, September 21, 2010 12:06:28 AM > Subject: $$Excel-Macros$$ VBA code required for Folder activity > > Hi Team, > > I have different files in different subfolder in a main folder. Now I > wish to collate all subfolder files to the Mainfolder. The macro has > to go inside each and every subfolder and copy the files and paste it > to a new folder. > > As a result of this the all files has to be pasted in one Folder. > > I request you all to help me in this activity. > > Ex: > > SubFolder 1 has 3 Files (aaa.Xml, bbb.xml, ccc.xml) > SubFolder 2 has 3 Files (111.xml, 222.xml, 333.xml) > SubFolder 3 has 5 Files (ddd.xml, eee.xml, fff.xml, ggg.xml, ttt.xml) > > Result > > The all files has to be pasted in one folder as i.e. > > Foler Master has to be 11 Files (aaa.Xml, bbb.xml, ccc.xml, 111.xml, > 222.xml, 333.xml, ddd.xml, eee.xml, fff.xml, ggg.xml, ttt.xml) > > By Mariappan > > Chennai - 06 > > -- >---------------------------------------------------------------------------------- >- > Some important links for excel users: > 1. Follow us on TWITTER for tips tricks and links : >http://twitter.com/exceldailytip > 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310 > 3. Excel tutorials at http://www.excel-macros.blogspot.com > 4. Learn VBA Macros at http://www.quickvba.blogspot.com > 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com > > To post to this group, send email to excel-macros@googlegroups.com > > <><><><><><><><><><><><><><><><><><><><><><> > HELP US GROW !! > > We reach over 7000 subscribers worldwide and receive many nice notes about > the >learning and support from the group.Let friends and co-workers know they can >subscribe to group at http://groups.google.com/group/excel-macros/subscribe > -- ---------------------------------------------------------------------------------- Some important links for excel users: 1. Follow us on TWITTER for tips tricks and links : http://twitter.com/exceldailytip 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310 3. Excel tutorials at http://www.excel-macros.blogspot.com 4. Learn VBA Macros at http://www.quickvba.blogspot.com 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com <><><><><><><><><><><><><><><><><><><><><><> HELP US GROW !! We reach over 7000 subscribers worldwide and receive many nice notes about the learning and support from the group.Let friends and co-workers know they can subscribe to group at http://groups.google.com/group/excel-macros/subscribe