VBA整合多个不同列的工作簿

时间:2016-04-07 20:33:25

标签: excel vba excel-vba

我想使用VBA将多个工作簿合并到一个主工作簿中,因为这将被重用。我怎样才能做到这一点。

这是一个例子

woorkbook

1 个答案:

答案 0 :(得分:0)

不是很优雅,但问题很模糊......

Sub merge()
    Dim aWkbk As Workbook
    Dim aWkSht As Worksheet
    Dim thisWkbk As Workbook

    Set thisWkbk = Application.Workbooks("Book1")
    For Each aWkbk In Application.Workbooks
        If aWkbk.Name <> "Book1" Then
            For Each aWkSht In aWkbk.Worksheets
                aWkSht.Copy after:=thisWkbk.Worksheets(thisWkbk.Worksheets.Count)
            Next aWkSht
        End If
    Next aWkbk
End Sub