AppleSource
New Member
- Joined
- Jan 10, 2021
- Messages
- 5
- Office Version
- 365
- 2010
- Platform
- Windows
I found the code quoted Below to generate multiple sheets from a template
ive got that working but id like to be able to also Generate 1x Workbook + name the workbook, then Move(so they would only exsist in new workbook, so not a copy) all the sheets that have been generated into the new workbook(only the generated pages).
Can anyone suggest a simple method of achieving this.
p.s Thanks @jbeaucaire for the awesome code
ive got that working but id like to be able to also Generate 1x Workbook + name the workbook, then Move(so they would only exsist in new workbook, so not a copy) all the sheets that have been generated into the new workbook(only the generated pages).
Can anyone suggest a simple method of achieving this.
p.s Thanks @jbeaucaire for the awesome code
Try this:
Code:Option Explicit Sub SheetsFromTemplate() Dim wsMASTER As Worksheet, wsTEMP As Worksheet, wasVISIBLE As Boolean Dim shNAMES As Range, Nm As Range With ThisWorkbook 'keep focus in this workbook Set wsTEMP = .Sheets("Template") 'sheet to be copied wasVISIBLE = (wsTEMP.Visible = xlSheetVisible) 'check if it's hidden or not If Not wasVISIBLE Then wsTEMP.Visible = xlSheetVisible 'make it visible Set wsMASTER = .Sheets("Master") 'sheet with names 'range to find names to be checked Set shNAMES = wsMASTER.Range("B3:B" & Rows.Count).SpecialCells(xlConstants) 'or xlFormulas Application.ScreenUpdating = False 'speed up macro For Each Nm In shNAMES 'check one name at a time If Not Evaluate("ISREF('" & CStr(Nm.Text) & "'!A1)") Then 'if sheet does not exist... wsTEMP.Copy After:=.Sheets(.Sheets.Count) '...create it from template ActiveSheet.Name = CStr(Nm.Text) '...rename it End If Next Nm wsMASTER.Activate 'return to the master sheet If Not wasVISIBLE Then wsTEMP.Visible = xlSheetHidden 'hide the template if necessary Application.ScreenUpdating = True 'update screen one time at the end End With MsgBox "All sheets created" End Sub