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:\Users\queqiaoshui\Desktop\excel\" & "*.xlsx"
my_file = Dir(my_path)


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


End Sub

  

posted @ 2019-01-15 10:36  queqiaoshui  阅读(290)  评论(0编辑  收藏  举报