Create multiple copies of a work book and rename each book as to a set list

Hdivision

New Member
Joined
Sep 16, 2011
Messages
5
Hi All
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Thanks for taking the time to review my post, I am absolutely confident that my question has been posted and answered, I apologize in advance if that is the case but I did try and look for the answer.
<o:p></o:p>
I have a workbook which has a bunch of sheets with data on them, I use the sheet as a template and for each new customer I copy the workbook and rename as per the customers reference name, I then place the work book within the customers respective folder.
<o:p></o:p>
My question are:
<o:p></o:p>
Can I use a macro to duplicate the template workbook and then rename the book as per a list or as per made folders?
<o:p></o:p>
This might be a bit too much but would a macro be able to rename the template and place the newly created template into specific folder?
<o:p></o:p>
If I am able to do the above and you share the macro with me, I will take you out for lunch the next time you are in <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:City w:st="on"><st1:place w:st="on">Brisbane</st1:place></st1:City>
<o:p></o:p>
Appreciate any help and on a last note “GO THE ALL BLACK RWC 2011”
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this:

Code:
Sub duplicateTemplate()
    fldr = "c:\local\myfolder\"
    tmp = "template.xls"
    With CreateObject("Scripting.FileSystemObject")
        Set listrange = Range("A2", Cells(Rows.Count, "A").End(xlUp))
        For Each fname In listrange.Cells
            MkDir fldr & fname
            .copyfile fldr & tmp, fldr & fname & "\" & fname & ".xls"
        Next fname
    End With
End Sub
Given a list of file names in column A, a folder called myfolder otherwise empty apart from a file called template.xls, this ought to do what you're after - create a set of folders and copy the template into them, changing its name as it goes. you can change all the paths etc. This should get you started, if you have any more questions, let me know.

HTH
 
Upvote 0
Hi Weaver<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
I am having a run error<o:p></o:p>
<o:p> </o:p>
Run-time error “53”:<o:p></o:p>
<o:p> </o:p>
Sub duplicateTemplate()<o:p></o:p>
fldr = "c:\local\myfolder\"<o:p></o:p>
tmp = "template.xls"<o:p></o:p>
With CreateObject("Scripting.FileSystemObject")<o:p></o:p>
Set listrange = Range("A2", Cells(Rows.Count, "A").End(xlUp))<o:p></o:p>
For Each fname In listrange.Cells<o:p></o:p>
MkDir fldr & fname<o:p></o:p>
.copyfile fldr & tmp, fldr & fname & "\" & fname & ".xls"<o:p></o:p>
Next fname<o:p></o:p>
End With<o:p></o:p>
End Sub<o:p></o:p>

<o:p> </o:p>
<o:p> </o:p>
I changed the yellow highlighted to the Dir locations on my computer<o:p></o:p>
<o:p> </o:p>
Am I to also add Dir for the red highlighted txt?<o:p></o:p>
<o:p> </o:p>
For example would the following code be correct using the following paths?<o:p></o:p>
<o:p> </o:p>
1 "c:\local\myfolder\" (this is the location where the template is held, so I change the path to reflect the folder holing my template<o:p></o:p>
2 "template.xls" (I need to change the name to reflect the name of my template).<o:p></o:p>
<o:p> </o:p>
3 I need to tell the macro where to store the new folder ?<o:p></o:p>
<o:p> </o:p>
If using the folowwing path c:\local\trial\<o:p></o:p>
<o:p> </o:p>
Would I need to add the following<o:p></o:p>
<o:p> </o:p>
Fldr = "c:\local\trial\"<o:p></o:p>
<o:p> </o:p>
If I need to change the following- .copyfile fldr & tmp, fldr & fname & "\" & fname & ".xls" - I have no idea on what to write<o:p></o:p>

Any assistance appreciated :)<o:p></o:p>
 
Upvote 0
If it's not possible for you to store the template in the destination folder of the new files (how the code is currently configured) then create another variable called fldr1 and name that for the location of the new files. Then the copy code becomes

Code:
For Each fname In listrange.Cells<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
  MkDir fldr1 & fname<o:p></o:p>
  .copyfile fldr & tmp, fldr1 & fname & "\" & fname & ".xls"<o:p></o:p>
Next fname<o:p></o:p><o:p></o:p>
In this case, fldr will be the path to the template file.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,912
Members
452,949
Latest member
beartooth91

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