我知道这个问题已经讨论了很多次,并且已经检查了几乎所有来源,但是我不知道为什么这个简单的代码不起作用。我想将工作表从一个工作簿复制到另一个工作簿。
Sub SimpleCode()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = Workbooks("C:\Users\File1.xlsx")
Set wb2 = Workbooks("C:\Users\File2.xlsx")
wb1.Sheets("File1Sheet1").Copy After:=wb2.Sheets("File2Sheet1")
End Sub
答案 0 :(得分:1)
假设两个文件都打开了,您只需要调用工作簿的名称,而不是全名即可。
Sub SimpleCode()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = Workbooks("File1.xlsx")
Set wb2 = Workbooks("File2.xlsx")
wb1.Sheets("File1Sheet1").Copy After:=wb2.Sheets("File2Sheet1")
End Sub