vba 复制或移动包含表格的一组工作表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26937729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:14:53  来源:igfitidea点击:

Copy or move a group of sheets that contain a table

excelvbaexcel-vba

提问by Selrac

I need to copy a group of sheets in Excel and past them into another Excel file. I have VBA code as follows:

我需要在 Excel 中复制一组工作表并将它们粘贴到另一个 Excel 文件中。我有 VBA 代码如下:

Sheets(Array("COVER", "A", "B", "C")).Select
Sheets(Array("COVER", "A", "B", "C")).Copy

but I get an error message when I run the macro:

但是当我运行宏时收到一条错误消息:

vba you cannot copy or move a group of sheets that contain a table

As the error states, I have some tables in the sheets. Is there as way to overcome this error?

由于错误状态,我在工作表中有一些表格。有没有办法克服这个错误?

回答by Selrac

thanks for the comments. I have resolved this question as follows:

感谢您的评论。我已经解决了这个问题如下:

Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("COVER").Copy After:=wb.Sheets(1)
ThisWorkbook.Sheets("A").Copy After:=wb.Sheets(2)
ThisWorkbook.Sheets("B").Copy After:=wb.Sheets(3)
ThisWorkbook.Sheets("C").Copy After:=wb.Sheets(4)
Set wb = Nothing

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
'Sheets("Sheet3").Activate
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True

Hope it helps someone else

希望它可以帮助别人

Thanks

谢谢