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]


    Sub Macro1()
    ' Macro1 Macro
    ' Macro recorded 10/17/2006 by Bryan
    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...


  • Re: Copy Worksheet To New Workbook & Save


    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.


  • 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

    Try this.

    Dim wb As Workbook
         Set wb = ActiveWorkbook
         wb.SaveAs "New Report.xls"


  • Re: Copy Worksheet To New Workbook & Save

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

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!