我有一本大约有10张纸的工作簿,并且我想用一个宏创建一个包含4张原始纸的新工作簿。
我有这个:
Sheets("1").Range("A1:xfd200").Copy
Workbooks.Add
ActiveSheet.Paste Destination:=Range("A1")
但这只会用我需要的一张纸来创建一个新的工作簿。
我将不胜感激。
谢谢!
答案 0 :(得分:0)
也复制其他工作表。
'copy first ws to no location to create the workbook then loop through
'and make copies of the others
dim ewb as workbook, w as long
with thisworkbook
.worksheets(1).copy
set ewb = activeworkbook
for w = 2 to 4
.worksheets(w).copy after:=ewb.worksheets(ewb.worksheets.count)
next w
'work with the new workbook as ewb
end with
'alternately, copy them into a new workbook all at once
Dim wss As Variant, nwb As Workbook
wss = Array("Sheet12", "Sheet13", "Sheet14", "Sheet15") '<~~ desired worksheets to copy
With ThisWorkbook
.Worksheets(wss).Copy
Set nwb = ActiveWorkbook
'work with the new workbook as nwb
End With