![从另一个工作簿复制 Excel 工作表](https://linux22.com/image/1594910/%E4%BB%8E%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%B0%BF%E5%A4%8D%E5%88%B6%20Excel%20%E5%B7%A5%E4%BD%9C%E8%A1%A8.png)
我尝试从另一个工作簿复制工作表,但我想开始从我知道名字的某张纸上抄写。
我尝试采用几种代码来复制所有工作表,但是却不行。
下面是我的代码示例:
Sub CreationDeBaseDeDonneesAvril2018()
Worksheets.Add After:=ThisWorkbook.ActiveSheet
Dim Counter As Integer
Dim ws As Worksheet
Dim FirstMonth As Integer
Dim i As Integer
Dim wb As Workbook
Set wb = Workbooks.Open(")
For Each ws In wb
If ws.Name = "01m" Then
Exit For
End If
Next
ws.Activate
Counter = activeworksheet.Count
For i = Counter To ActiveWorkbook.Worksheets.Count
Worksheets(i).Copy After:=ThisWorkbook.Worksheets(1)
Next
End Sub
提前感谢你的帮助
答案1
此 VBA(宏)代码将帮助您将某些工作表从关闭的工作簿复制到当前工作簿。
Sub CopyFromClosedWBK()
Dim wbSource As Workbook
Dim wbTarget As Workbook
Dim Sht As Worksheet
Set wbTarget = ThisWorkbook
Set wbSource = Workbooks.Open("C:\FolderName\WhicheverFile.xlsm")
wbSource.Sheets("Sheet2").Copy After:=wbTarget.Sheets("Sheet4")
wbSource.Close
End Sub
注意:
- 带有源书的文件路径以及文件夹和工作表名称都是可编辑的。
- 您可以使用
wbSource.Sheets("Sheet2").Copy After:=
命令行添加任意多张要复制的工作表。