MACRO to copy data.xls file from different subfolders to dest folder and rename the file

sanjay1982

New Member
Joined
May 2, 2013
Messages
6
I would like to copy every file named "data.xls" from every subfolder found in the folder c:\test\ and want to save in "dest" folder with file name "data_1.xls","data_2.xls"....so on so. Each sub folder is named as 01022013,02022013,03022013.....and all are contain the file "data.xls"
 
Code:
Sub a()
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   oldpath = "c:\test\"
   newpath = "c:\dest\"
   Set mainFolder = objFSO.GetFolder(oldpath)
   For Each mySubFolder In mainFolder.subfolders
     Name = "data.xls"
     p=instrrev(mySubFolder,"\")
     Name1 = "data_" & right(mySubFolder, len(mySubFolder)-p) & ".xls"
     FileCopy mySubFolder [COLOR=#ff0000]& "\"[/COLOR] & Name, newpath & Name1
   Next
End Sub

Hi Mate,

I have a similar problem.

I have a file in directory C:\Test

Name is File.xls

I want to re-name it to 'File_1.xls' first

Then copy different file called Data.xls to new location called C:\Done

Sorry to give you trouble mate. thanks in advance ( i am an excel noob )
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
Name C:\Test\File.xls As C:\Test\File_1.xls

FileCopy C:\Test\Data.xls, C:\Done\Data.xls
 
Upvote 0
Hi Patel,

Im looking for your help.

My Question:

MACRO to copy all .xls file from different subfolders to Single dest folder

Thanks in Advance
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top