简体   繁体   中英

Paste sheet copied from an open workbook into an existing non open workbook

I am trying to copy "Sheet1" from the workbook I have open, labelled "source.xlsm", and paste after the last sheet of my existing workbook which is not open at the time of running, labelled "target.xlsx".

I have the below code and it seems the whole "C:\\" directory does nothing. Is it even possible to put a directory in? I cannot find a way to do this without having the Target.xlsx open.

ActiveSheet.Select
ActiveSheet.Copy After:=Workbooks("C:\Target.xlsx").Sheets("FirstSheet")

You already figured it out, but a suggested edit:

Dim wb As WorkBook
''Open 2nd Workbook
Set wb = Workbooks.Open(Filename:="C:\Archive.xlsx")

''Copy To Different Workbook
Workbooks("Source.xlsx").Sheets("Source").Copy _
         After:=wb.Sheets("Archive")

''Close 2nd Workbook
wb.Save
wb.Close

Answered my own question with the helpful information provided by Tim.

''Open 2nd Workbook
Workbooks.Open Filename:="C:\Archive.xlsx"

''Copy To Different Workbook
Workbooks("Source.xlsx").Sheets("Source").Activate
ActiveSheet.Copy After:=Workbooks("Archive.xlsx").Sheets("Archive")

''Close 2nd Workbook
Workbooks("Archive.xlsx").Sheets("Archive").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM