Reputation: 13
I know this question is discussed many times and I have checked almost all sources but I don't know why this simple code does not work. I want to copy a worksheet from one workbook to another.
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
Upvotes: 1
Views: 171
Reputation: 4299
Assuming that both files are open you only need to call the name of the workbooks, not the full name:
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
Upvotes: 1