MACRO to create copy of files and rename them

afzalw

New Member
Joined
Jul 24, 2012
Messages
20
Can excel MACRO make copies of a file. I want to give path of one file and ask Excel to make copies of this file in same folders.
Then rename these files.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
why copy, then rename ? no possible in the same folder, you have to copy with new name
 
Upvote 0
I was hoping something we do normally in windows when we copy file in same folder. Windows itself renames file (ABC) to 'ABC - Copy' next one ABC - Copy(2) and so on. Commands for copy and then paste a file would work, do you know something that can copy paste a file.
 
Upvote 0
Code:
Sub copyfileinSameFolder()
Set fs = CreateObject("Scripting.FileSystemObject")
oldpath = "D:\test"
newPath = "D:\test"
Prefix = "1_"
Set f = fs.getfolder(oldpath)
Set NFile = f.Files
For Each pf1 In NFile
  NameFile = pf1.Name
  filecopy oldpath & "\" & NameFile, newPath & "\" & Prefix & NameFile
Next
End Sub
 
Upvote 0
Code:
Sub copyfileinSameFolder()
Set fs = CreateObject("Scripting.FileSystemObject")
oldpath = "D:\test"
newPath = "D:\test"
Prefix = "1_"
Set f = fs.getfolder(oldpath)
Set NFile = f.Files
For Each pf1 In NFile
  NameFile = pf1.Name
  filecopy oldpath & "\" & NameFile, newPath & "\" & Prefix & NameFile
Next
End Sub

Hi,
As in the above macro i need it to copy>paste & rename the filess till the end of a filename list is reached.
can you please help me ?
 
Upvote 0
I need a macro to copy a file in a folder and make multiple copies of it in that very folder.


Step 1 : Select the file you want to make copies of.
Step 2 : Select the destination folder / auto select it based on the folder of the file in Step 1.
Step 3 : List all the filenames in Column A starting from Cell A2 (Header Cell : FILENAMES)
Step 3 : Run Macro that will pick up the filenames listed in a column starting from Cell A2
and create multiple copies of that file with the names in Column A.

This macro should loop till the end of list in Column A is reached.

** The files can be of any type.

New Thread posted at : http://www.mrexcel.com/forum/excel-questions/800433-macro-copy-pasete-rename.html#post3913544
 
Upvote 0
Can you please explain the what each script line does? I am very basic to Macro and the below works for me. But will be good to know as what actually each line does. Thanks J

Can you please explain the what each script line does? I am very basic to Macro and the below works for me. But will be good to know as what actually each line does. Thanks J

Code:
Sub copyfileinSameFolder()
Set fs = CreateObject("Scripting.FileSystemObject")
oldpath = "D:\test"
newPath = "D:\test"
Prefix = "1_"
Set f = fs.getfolder(oldpath)
Set NFile = f.Files
For Each pf1 In NFile
  NameFile = pf1.Name
  filecopy oldpath & "\" & NameFile, newPath & "\" & Prefix & NameFile
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,749
Messages
6,167,967
Members
452,158
Latest member
MattyM

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