[英]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". 我试图从已打开的工作簿中复制“ Sheet1”,标记为“ source.xlsm”,并粘贴到现有工作簿的最后一张纸上,该工作簿在运行时尚未打开,并标记为“ target.xlsx”。
I have the below code and it seems the whole "C:\\" directory does nothing. 我有下面的代码,似乎整个“ C:\\”目录没有任何作用。 Is it even possible to put a directory in?
甚至可以放置目录吗? I cannot find a way to do this without having the Target.xlsx open.
如果没有打开Target.xlsx,我无法找到一种方法。
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. 提姆(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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.