Copy and rename file from list

Wil Moosa

Well-known Member
Joined
Aug 11, 2002
Messages
893
I have one file; Mother.xls

Mother.xls has on sheet(6) a list with names of all the employees. I want to create as many copies of Mother.xls as found on the list on sheet(6) each file carrying the name as mentioned on the list.

The following code does the trick for me:

Sub Aanmaken_peroonlijk_kwartaaloverzicht_Batch()
Sheets(6).Select
Range("A1").Select

Do
Application.Run "Aanmaken_peroonlijk_kwartaaloverzicht"
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = Empty
Range("a1").Select

MsgBox " Alle bestanden zijn aangemaakt." _
, vbInformation, " Groene Kruis Thuiszorg"
End Sub

Sub Aanmaken_persoonlijk_kwartaaloverzicht()
ThisWorkbook.SaveAs ("C:\Documents and Settings\Wil Maassen\Bureaublad\Kwartaaloverzichten\" & ActiveCell.Value & ".xls")
End Sub

Two things I can not figure out.
*When an error pops up (File already exists, Do you want to skip, Yes.... ) the loop comes to a hold. Can I prevent this? How?
*In every copy the sheet(6) needs to be deleted. Where in the loop I need to add what code to achieve this?
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

To prevent the error you'll have to use an if statement to delete the file before the ...SaveAs, such as :

If File Exists "C:\Documents and Settings\Wil Maassen\Bureaublad\Kwartaaloverzichten\" & ActiveCell.Value & ".xls" Then
Kill "C:\Documents and Settings\Wil Maassen\Bureaublad\Kwartaaloverzichten\" & ActiveCell.Value & ".xls"
EndIf

...SaveAs


To achieve the deletion of the sheet where the list with file names is in you'll have to use the macro as a personal macro.

Number the list-items from 1 to ? and loop through the list by number.

Success,
Erik
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,697
Messages
6,167,702
Members
452,132
Latest member
Steve T

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