从另一个工作簿复制 Excel 工作表

从另一个工作簿复制 Excel 工作表

我尝试从另一个工作簿复制工作表,但我想开始从我知道名字的某张纸上抄写

我尝试采用几种代码来复制所有工作表,但是却不行。

下面是我的代码示例:

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:= 命令行添加任意多张要复制的工作表。

相关内容