Copy Worksheet To New Workbook & Save

  • I have a workbook with a worksheet named "Report"... this sheet and it's macros generate a report from data on another sheet...


    I'm adding a button to copy the (filled) Report sheet to a new workbook, rename the new sheet in the new workbook "Rep[Name]", then save and close the new workbook...


    I've recorded a maco of me doing these tasks manually, but what's recorded seems very generic, and does not seem to specify what's really occurring...
    For example (in part);
    > Rightclick on the Report tab
    > Move or Copy
    > To Book: (new book)
    > [x]Create a Copy
    > [OK]


    yields:

    Code
    1. Sub Macro1()
    2. '
    3. ' Macro1 Macro
    4. ' Macro recorded 10/17/2006 by Bryan
    5. '
    6. Sheets("Report").Select
    7. Sheets("Report").Copy
    8. End Sub


    This recorded macro does not specify (new book), or Before:"Sheet1" as was the result of my actions... and when replayed back, only makes a copy in the active workbook, before the active sheet...


    Please offer suggestions as to what the copy code should look like, as the recorder macro clearly is not it...


    TiA,

  • Re: Copy Worksheet To New Workbook & Save


    Bryan


    As far as I can see that code should create a new workbook containing only 1 sheet, Report.


    The Copy method has 2 optional arguments, Before and After.


    These determine where the worksheet(s) are copied to.


    If omitted a new workbook is created.

    Boo!:yikes:

  • Re: Copy Worksheet To New Workbook & Save


    When a new workbook is created via .Copy, is the focus changed to that new workbook?, or does the new workbook then have to be .Selected?...
    If the latter, how do you refer to this new workbook of an unknown name?

  • Re: Copy Worksheet To New Workbook & Save


    Thanks for the input...
    It's now working just fine, with the following code;