Generating new file with multiple sheet template

Report
-
Posts
1326
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
November 28, 2021
-
Hello,

I have a file that is currently generating new files based on a template file + a list of names.

The problem is that the file is generating a new file but only for the first sheet of the template and the template file has 4 sheets.

This is what I have:

Sub SaveMasterAs()

 Dim wb As Workbook

 Dim rNames As Range, c As Range, r As Range

 Set rNames = Worksheets("Sheet1").Range("A2", Worksheets("Sheet1").Range("A2").End(xlDown))

 Set wb = Workbooks.Open(ThisWorkbook.Path & "\template_2021.xlsm")

 For Each c In rNames

 With wb

 .SaveAs Filename:=ThisWorkbook.Path & "\templates\" & c.Value & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

 End With

 Set wb = ActiveWorkbook

 Next c

 wb.Close

End Sub



Can you please guide me in the right direction?

1 reply

Posts
1326
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
November 28, 2021
241
Hello Ana,

I created a mock-up of your "template_2021" file and used your code to create the copies.
It worked well and there weren't any problems. All sheets were copied so I don't know why you are having problems with your code.
Are any error messages arising?

Cheerio,
vcoolio.
1
Thank you

Glad we were able to help! Love us? Write us a review! Rate CCM

CCM 2821 users have said thank you to us this month