如何打开多个工作簿并将工作表内容复制到新的聚合工作簿

时间:2015-08-24 20:27:35

标签: excel vba excel-vba

Sub test1()
Dim LastRow As Long
Dim LastRow2 As Long
  Do While Filename <> ""
    Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
    For Each Sheet In ActiveWorkbook.Sheets
        If Sheet.Name = "Orders" Then
            LastRow = ThisWorkbook.ActiveSheet.Cells(ThisWorkbook.ActiveSheet.Rows.Count, "AK").End(xlUp).Row
            Range("AP" & LastRow).Select
            Range(Selection, Cells(1)).Select
            Range(Selection, Selection.End(xlUp)).Select
            Selection.Copy
            LastRow2 = Workbooks("Book1").Sheets("Sheet1").Cells(ThisWorkbook.ActiveSheet.Rows.Count, "AK").End(xlUp).Row
            Range("A" & LastRow + 1).Select
            Selection.Paste
            'Sheet.Copy After:=ThisWorkbook.Sheets(1)
        End If
    Next Sheet
    Workbooks(Filename).Close
    Filename = Dir()
  Loop 
End Sub

以上是我目前的代码。以下是我要完成的任务:

  • 打开工作簿
  • 复制工作簿中“订单”表的内容
  • 将“订单”表单的内容粘贴到新工作簿的下一个空行中(这将是所有已打开工作簿的“订单”表的汇总
  • 重复

我的问题与此处回答的问题不同:Excel vba: copy sheet and get resulting sheet object?

原因是我不希望复制实际的工作表对象,只复制其内容。

0 个答案:

没有答案