我需要帮助将工作表从一个excel工作簿复制到另一个工作簿。目前,这是我的代码,但它没有运行:
Sub Code()
Workbooks.Open Filename:="C:\Users\xxx\Desktop\w1.xlsm"
Sheets (Array("Sheet1", "Sheet2"))
Copy after:=Workbooks("w2.xlsm").Sheets(Sheets.Count)
Workbooks("Client Info Template.xlsm").Close savechanges:=False
End Sub
答案 0 :(得分:0)
不要将Sheets...
和Copy ...
作为两行,而是尝试一行:
Sheets(Array("Sheet1", "Sheet2")).Copy After:=Workbooks("w2.xlsm").Sheets(Sheets.Count)
这可能仍然不起作用,或者至少不可靠,因为Sheets.Count
可能超过目标工作簿中的工作表数量,因此最好完全限定所有对象:
Sub Code()
Dim w1 as Workbook, w2 as Workbook
Set w1 = Workbooks.Open(Filename:="C:\Users\xxx\Desktop\w1.xlsm")
Set w2 = Workbooks.Open(Filename:="C:\Users\xxx\Desktop\w2.xlsm") '## Modify as needed
w1.Sheets(Array("Sheet1", "Sheet2")).Copy After:=w2.Sheets(w2.Sheets.Count)
End Sub