Results 1 to 5 of 5

Thread: Solved: Copy entire sheet to a new workbook

  1. #1
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location

    Solved: Copy entire sheet to a new workbook

    Im trying to make a toolbar with an option that when being selected should copy the activesheet to a new workbook. I tried using the record button but the code of the paste part is lost.

    I thought it would be something simple like
    [VBA]
    activesheet.copy (application.workbooks.add)
    [/VBA]
    please help
    meanwhile Im copying the whole cells
    [VBA]
    activeworksheet.cells.copy
    newsheetonnewbook.paste
    [/VBA]
    but some properties are lost. thanks

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    [VBA]Option Explicit
    Public Sub CloneActiveSheet()
    Excel.ActiveSheet.Copy
    End Sub[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    This seems to work:

    [VBA]
    Sub CopyThisSheet()
    Cells.Select
    Selection.Copy
    Workbooks.Add
    Cells.Select
    ActiveSheet.Paste
    End Sub
    [/VBA]

    Regards

    Paul Ked
    Semper in excretia sumus; solum profundum variat.

  4. #4
    VBAX Contributor
    Joined
    Aug 2006
    Posts
    120
    Location
    thanks Oorang, this is the first time i see "Excel" in any code

  5. #5
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Hi Makako,
    It's not really necessary , I just happen to work with projects that use Access & Excel simultaneously and/or run multiple Excel processes at once. Since there are a few naming overlaps between Access/Excel (notably "Application") and if you are using multiple processes you need to be explicit about which one, I just got in the habit. Plus it's easier to remember syntax when you have to nice intellisense prompting you. It's mostly just a style thing. [vba]ActiveSheet.Copy [/vba] Works just as well
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

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