Link to home
Start Free TrialLog in
Avatar of Jenkins
JenkinsFlag for United States of America

asked on

Macro to retrieve the names of files

I need a macro that will do the following:

MyFolder1 has 5 excel files in it.  They are named:

File1
File2
File3
File4
File5

MyFolder2 currently has 1 file in it.  It is named:
Testfile.

Using a macro in the Testfile file, I need to make copies of the Testfile file, give each one the same name as the files in MyFolder1 and place the newly named files in MyFolder2 so that I wind up with the following in MyFolder2:

File1
File2
File3
File4
File5

And, no I can't just make copies of the files in MyFolder1.  I need to make copies of the Testfile file and rename them.

So what I'm looking for is how to cycle through MyFolder1, get the names of the files programmatically, create copies of the Testfile so that I wind up with 5 of them, rename them to match the names of the files in MyFolder1 and place the newly-created files in MyFolder2.  Thank you.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

what's the file extension for the files in folder: MyFolder1 ? is it .xls or .xlsx etc?

is there only 5 files to be replicated in folder MyFolder1 based on the content of file: Testfile in MyFolder2?

are those mentioned file names above are fixed?
Avatar of Jenkins

ASKER

They are all .xlsm

For illustration, I said there 5 files. There are actually many more but I can always change the count in the loop.   The source files are in MyFolder1.  The replicated files will be in MyFolder2.  The file used for the replicatons is in MyFolder2.

I indicated the exact names of the files.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or do you want based on what files (with file extension .xlsm?) that available in MyFolder1 and "replicate" it to MyFolder2 accordingly?