Reputation: 15
As the title says, the below is my attempt at (within my active workbook) opening another workbook, copying its contents, then pasting it within my current workbook's 2nd sheet. But I'm unable to pass the act of pasting. I've been unable to find relevant examples online to this particular case.
Sub SL()
Dim x As Workbook
Set x = Workbooks.Open("C:\Stuff.xlsx")
x.Sheets("SheetName").Cells.Copy
ActiveWorkbook.Sheets("Sheet2").Cells.PasteSpecial
End Sub
Can someone just explain what I should be putting in there, please?
Upvotes: 0
Views: 50
Reputation: 7735
I believe the following will give you a helping hand to achieve what you expect:
Sub SL()
Dim x As Workbook
Set x = Workbooks.Open("C:\Stuff.xlsx")
x.Sheets("SheetName").Cells.Copy
'does your workbook actually have a Sheet named "SheetName"?
'if not, you need to reference the sheet that you want to copy
ThisWorkbook.Sheets("Sheet2").Cells.PasteSpecial
x.Close False
'close your "Stuff" workbook without saving
End Sub
Upvotes: 1