[英]EXCEL VBA: Copy Sheet from a workbook to another workbook in different location
I am trying to copy a whole sheet from one Excel file to a sheet in another. 我正在尝试将整个工作表从一个Excel文件复制到另一个工作表中。 Following is the code I wrote which doesn't work.
以下是我编写的无效代码。 Please suggest changes.
请提出更改建议。
Sub copyallwos()
Dim wkbSource As Workbook
Dim wkbDest As Workbook
Dim shttocopy As Worksheet
Dim wbname As String
Set wkbSource = Workbooks.Open("C:\Users\AV\Documents\New folder\SCADA Wos.xlsm")
Set wkbDest = Workbooks("C:\Users\AV\Documents\New folder\MASTER.xlsm")
'perform copy
Set shttocopy = wkbSource.Sheets("tt")
shttocopy.Copy
wkbDest.Sheets("SCADAWOs").Select
ActiveSheet.Paste
End Sub
Try this under 'perform copy
在
'perform copy
下尝试
wkbSource.Sheets("tt").Copy After:=wkbDest.Sheets("SCADAWOs")
You can also insert the sheet before your "SCAD..." sheet, just change After:=
to Before:=
. 您也可以在“ SCAD ...”工作表之前插入工作表,只需将
After:=
更改为Before:=
。 Also, if you don't necessarily know a sheet name in the destination workbook, you can use After:=Wkbdest.sheets(sheets.count)
which will instert it after the last Worksheet. 另外,如果您不一定在目标工作簿中知道工作表名称,则可以使用
After:=Wkbdest.sheets(sheets.count)
,它将在最后一个工作表之后插入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.