简体   繁体   English

Excel将活动工作表和指定工作表复制到新工作簿

[英]Excel Copy active sheet and specified sheets to new workbook

im trying to copy the active sheet and 2 specified sheets to a new workbook and then have the macro to continue to run on the new workbook to change a few things before i save it 我试图将活动工作表和2个指定工作表复制到新工作簿,然后让宏继续在新工作簿上运行以更改一些内容,然后再保存它

i want to copy the sheets by the sheets codenames 我想按工作表代号复制工作表

  • 1st Sheet 3 to copy this will be the "active sheet" 复制的第一张纸3将是“活动纸”
  • 2nd Sheets codename is "DropDown_Sheet_1_VB" 第二张工作表的代号为“ DropDown_Sheet_1_VB”
  • 3rd Sheets codename is "Control_Sheet_VB" 第三张纸的代号为“ Control_Sheet_VB”

Example Code. 示例代码。

Sub Create_Work_Order()

Workbooks.Add

ActiveSheet.Copy 'copy to new workbook
DropDown_Sheet_1_VB.Copy 'also copy to new workbook
Control_Sheet_VB.Copy 'also copy to new workbook

Dim NewWB As Workbook

NewWB.ActiveSheet.Range("A1").Copy 'do stuff on new workbook
NewWB.Save

End Sub

I don't know what is the stuff at the end other than copying A1 range but I put it there too. 除了复制A1范围外,我不知道最后还有什么内容,但我也把它放在那儿了。

You simply need to assign the workbook object (wrk in my sample, NewWB in your sample - variable name doesn't matter) at the beginning and tell the Copy method where to copy. 您只需要在开始时分配工作簿对象(在我的示例中为wrk,在示例中为NewWB-变量名称无关紧要),并告诉Copy方法在何处复制。 You will see that I specified first parameter - which is :Before - as wrk.Worksheets(1), so copied sheets are copied just before the first worksheet in the new workbook. 您将看到我将第一个参数-Before-指定为wrk.Worksheets(1),因此复制的工作表被复制到新工作簿中的第一个工作表之前。

Sub Create_Work_Order()
Dim currentWrk As Workbook
Dim wrk As Workbook

Set currentWrk = ActiveWorkbook
Set wrk = Workbooks.Add

currentWrk.ActiveSheet.Copy wrk.Worksheets(1)
DropDown_Sheet_1_VB.Copy wrk.Worksheets(1)
Control_Sheet_VB.Copy wrk.Worksheets(1)

'wrk.ActiveSheet.Range("A1").Copy 'do stuff on new workbook
wrk.Save

' EDIT: I added following to change the functions to refer to the new file
wrk.ChangeLink currentWrk.FullName, wrk.FullName, xlExcelLinks  
wrk.Save


End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将活动工作表复制到没有公式的新工作簿 - Copy active sheet to new workbook without formulas 如何将活动工作表的内容复制到新工作簿? - How to copy the contents of the active sheet to a new workbook? 将特定的Excel工作表作为值复制到新工作簿中 - copy specific excel sheets to a new workbook as values Excel VBA宏可将工作簿工作表中的特定行复制到新的摘要工作表中…几乎可以工作 - Excel VBA macro to copy specific rows from workbook sheets into new summary sheet…almost works Excel VBA 将指定的一组工作表复制到新工作簿/从副本中排除工作表 - Excel VBA copying specified set of worksheets to new workbook/excluding sheet from copy 如何使用 vbs 脚本复制活动的 Excel 工作表并将其保存到新工作簿中? - How to copy an active excel sheet and save it into a new workbook using a vbs script? VBA - 根据汇总 Excel 表格上的条件,将工作簿中的不同模板工作表复制到另一个工作簿的多张工作表中 - VBA - copy different template sheets from a workbook, into multiple sheets of another workbook based on criteria on a summary excel sheet 如何将模板工作表从Excel文件复制到活动工作簿 - How to copy templated sheet from excel file to active workbook 将数据从许多行和指定的列复制到新工作簿中的工作表 - Copy data from a number of rows and specified columns to a sheet in new workbook 将文件夹中所有工作簿的活动工作表复制到新工作簿 - Copy Active sheet of all workbooks in a folder to a new workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM