VBA 合并工作簿

Posted queqiaoshui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA 合并工作簿相关的知识,希望对你有一定的参考价值。

Sub 合并工作簿()

Dim my_path, my_file As String
Dim ws As Worksheet
Dim wb As Workbook
Dim twb As Workbook

Set twb = ThisWorkbook  ‘设置twb 为当前代码所在工作簿

my_path = "C:UsersqueqiaoshuiDesktopexcel" & "*.xlsx"
my_file = Dir(my_path)


Do While my_file <> ""
    Set wb = Workbooks.Open("C:UsersqueqiaoshuiDesktopexcel" & my_file)  ‘打开遍历到的工作簿并赋给wb
    
    wb.Sheets.Copy , twb.Worksheets(twb.Worksheets.Count) ‘ 把打开的工作簿中的表复制到代码所在工作簿
    wb.Close
    
    my_file = Dir
   Application.ScreenUpdating = True
Loop


End Sub

  

以上是关于VBA 合并工作簿的主要内容,如果未能解决你的问题,请参考以下文章