Copy files in sub folders to a specific directory

A

andreashermle

Dear experts:

I got more than 50 subfolders located under the following main
folder's path:

C:\test\MainFolder\...
....SubFolder_1
....SubFolder_2
....SubFolder_3
....SubFolder_4
....SubFolder_n

There is (1) one xlsx-file in every subfolder.

I now would like to be able via a Macro to copy the xlsx-files located
in the sub folders directly into the following directory:

C:\test\MainFolder.

Is this feasible?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
P

Peter T

You can use the Name function, from help
Name oldpathname As newpathname

something like this, untested!

s1 = C:\test\MainFolder\SubFolder_#\myFile.xls"
s2 = C:\test\MainFolder\myFile"

for i = 1 to 50
sOld = replace(s1, "#", cStr(i))
sNew = s2 & "myFile_" & right("0" & i, 2) & ".xls"
Name sOld as sNew
Next

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top