Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50076

Create a new sheet in my workbook by pushing a button but use a template

$
0
0
Hi i have been trying to figure this out for a while, I have managed to get the button to create a new sheet and put it next in the order of sheets but my problem is the sheet i create is blank,
I would like the new sheet to use the template i have made.

i have the following VBA so far but would love help to put my template on, it is simply called Template,

Code:

Private Sub cmdAddC_Click()
Dim newSheet As Worksheet
Dim newName As String
Do
    newName = Application.InputBox("What is the first line of Address?", Type:=2)
    If newName = "False" Then Exit Sub: Rem cancel pressed
   
  Set newSheet = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(1))
   
    On Error Resume Next
        newSheet.Name = newName
        newName = Error
    On Error GoTo 0
   
    If newName <> vbNullString Then
        Application.DisplayAlerts = False
            newSheet.Delete
        Application.DisplayAlerts = True
        MsgBox newName
    End If
Loop Until newName = vbNullString
Unload Me ' Close the Form
End Sub

I would be greatfull for any help thanks,

Chris

Viewing all articles
Browse latest Browse all 50076

Trending Articles