简体   繁体   中英

Copy a specific sheet to a new workbook

How would could one write a macro that will copy sheet 2 from workbook 1 and create a new workbook and paste that sheet into the new workbook If i click on a button I have added at the bottom of sheet 1, workbook 1.

Edit This code copies the active sheet(which is not the sheet I want) and does the rest perfectly by prompting to save as, which is cool, However I need to copy sheet 2 and not the active sheet.

Sub GetQuote()

   Dim activeWB As String
   Dim thisSheet As String

   activeWB = ActiveWorkbook.Name
   thisSheet = Workbooks(activeWB).ActiveSheet.Name
   Workbooks.Add
   Workbooks(activeWB).Sheets(thisSheet).Copy _
   Before:=ActiveWorkbook.Sheets(1)
   Application.Dialogs(xlDialogSaveAs).Show
   ActiveWorkbook.Close

End Sub

This should do the job:

Sub GetQuote()
    ThisWorkbook.Sheets("Sheet2").Copy
    Application.Dialogs(xlDialogSaveAs).Show
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM