Consulting

Results 1 to 5 of 5

Thread: Solved: Copy sheets but without the code..

  1. #1
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location

    Solved: Copy sheets but without the code..

    Hi folks,

    I use the code below to copy sheets from the active workbook to another. However... that if that sheet contains VB code, that is also copied. Is there an option to copy WITHOUT code?

    [VBA]Sub CopySheets()
    Dim BkName As String
    Dim NumSht As Integer
    Dim BegSht As Integer
    BegSht = 1
    NumSht = 6
    BkName = ActiveWorkbook.Name
    For x = 1 To NumSht
    Workbooks(BkName).Sheets(BegSht).Copy _
    Before:=Workbooks("Test.xls").Sheets(1)
    Next
    End Sub[/vba]

    Greetings,

    Thymen

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Just do a copy/paste of the cells instead. Something like this.

    [vba]
    Workbooks("Test.xls").Sheets.Add Before:=Workbooks("Test.xls").Sheets(1)
    Workbooks(BkName).Sheets(BegSht).Cells.Copy _
    Destination:=Workbooks("Test.xls").Sheets(1).Range("A1")

    [/vba]

  3. #3
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location
    Thanks!
    I used yr sample to create some new code. I added an add-sheet and rename-sheet to it. That is why I tried with the copy sheet way first: it adds a sheet while retaining the original name.
    Anyhow, it's solved. I'll put the new code in here tomorrow. Bedtime now....

    Thymen

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Glad to help

    Take Care

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I generally recommend copying the sheet and deleting any code. Copy/paste has some deficiencies, plus I think it's just clunky. There is some good code in the KB and around the forum on deleting code from worksheets and such. Also, Chip Pearson's site has a good section on deleting code from a file/module(s).

Posting Permissions

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