Consulting

Results 1 to 4 of 4

Thread: Solved: Adding and Naming a Worksheet using VBA

  1. #1

    Solved: Adding and Naming a Worksheet using VBA

    Hi there, - I have 2 questions

    1. Could anyone tell me how to copy and paste a template worksheet within a workbook and name it using VBA?

    2. Is it possible to hide a worksheet (the template used for the new copies) within the workbook so users can't use or edit it?)


    Here is the Logic:

    1. Copy WorkSheet A
    2. Paste NewCopySheet After (SheetCount)
    3. ReName NewCopySheet "Link x" (x = 1 for first sheet, x = 2 for 2nd sheet ...)

    Thanks in advance for your help!

  2. #2
    VBAX Regular HaHoBe's Avatar
    Joined
    Aug 2004
    Location
    Hamburg
    Posts
    89
    Location
    Hi, maxhayden,

    enter the VBIDE and give Visible for that Sheet a 2 - xlSheetVeryHidden. Sheet can only be made visible by using the VBE or by running a macro.

    With Worksheets("A")
       .Visible = xlSheetVisible
       .copy after:=Sheets(Sheets.Count)
       ActiveSheet.Name = "Link " & Worksheets.Count
       .Visible = xlSheetVeryHidden
    End With
    Ciao,
    Holger

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [VBA]Sub AddNewSheets()
    Dim TotalSheets As Variant
    TotalSheets = Worksheets.Count - 1
    Worksheets("Blank Sheet").Activate
    ActiveSheet.Copy after:=Worksheets("Page " & TotalSheets)
    Worksheets("Blank Sheet (2)").Activate
    ActiveSheet.Name = "Page " & TotalSheets + 1
    ActiveSheet.Visible = True

    End Sub[/VBA]

    template sheet is hidden in the attachment
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Hi HaBoHe,

    Thank you very much for that peice of code. It works perfectly.

    I modified it to take into account the other pages in the workbook:

    Eg: "Link " & Worksheets.Count - 2

    Thanks again!

    Max

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •