将多个工作簿合并为一个工作簿 (已关闭)

将多个工作簿合并为一个工作簿 (已关闭)

我需要将多个工作簿合并为一个工作簿。

源工作簿具有唯一的工作表名称 =“job”

目标工作簿有多个工作表名称

下面的代码有两个问题,

  1. For循环不起作用
  2. 在目标工作簿中粘贴数据会创建一个新工作表。但我需要将数据粘贴到现有工作表中。

Sub combine()

'destination worksheets    
    Dim Ar As Worksheet
    Dim nr As Worksheet
    Set Ar = ThisWorkbook.Sheets("sheetAr")
    Set nr = ThisWorkbook.Sheets("Sheetnr")
    'Source workbooks
    Dim FolderPath As String
    Dim Filename As String
    Application.ScreenUpdating = False
    FolderPath = Environ("userprofile" & "\Desktop\Copy")
    Filename = Dir(FolderPath & "*.xlsx*")
    
    Do While Filename <> ""
    Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
    Dim ws As Worksheet
    Dim AW As Workbook
    
    Set AW = ActiveWorkbook
    Set ws= ActiveWorkbook.Sheets("Job")
    
     For Each AW In ws
     AW.Activate
     Cells.ShownAll
     ws.Copy Ar
     Next AW
     Workbooks(Filename).Close savechanges = True
     Filename = Dir()
    Loop
    Application.ScreenUpdating = True
    End Sub`

相关内容