如何将一个工作簿中的一个工作表复制到另一个工作簿中

我有两个单独的工作簿,一个名为ActiveWorkbook,一个名为Terminated Workbook。 我想要做的是在ActiveWorkbook – Templatesheet上创build一个复制button,它将要求用户将哪个表复制并复制到TerminatedWokbook中,并将其命名为原始表单。

我有这样的代码,因为我是非常新的macros,因此它不起作用。 谢谢

Sub CopytoTernimal() Dim CopyName As String CopyName = InputBox("Please enter the name of sheet which will copy to ternimal") Sheets("CopyName").Copy Before:=Workbooks("Terminated Employees").Sheets(1) End Sub 

好的,这是完整的代码

 Dim CopyName As String CopyName = InputBox("Please enter the name of sheet which will copy to ternimal") Dim thisSheet As Worksheet 'you must be sure CopyName is typed correctly, or it wont find the sheet 'also be sure the Activeworkbook name is correctly typed. Set thisSheet = Workbooks("ActiveWorkbook").Worksheets(CopyName) 'copy this sheet thisSheet.Rows.Copy Dim NewSheet As Worksheet Set NewSheet = Workbooks("Terminated Employees").Worksheets.Add() NewSheet.Name = thisSheet.Name NewSheet.Paste 

要成为一个button,转到主Excel窗口,开发人员选项卡,并插入一个Active X Button 。 (使用活动工作簿)然后在design mode ,双击该button。 click event会自动生成,所以你把这个代码放在那个子里面。 之后,禁用design mode (也在主窗口的开发人员选项卡中)。 当你点击button时,代码将被调用。