在同一个目录下,复制所有工作簿第一张表。适合只有一张表的汇总。
Sub 按钮1_Click()
Dim path, file, count, wb As Workbook
'冻结屏幕,以防屏幕抖动
Application.ScreenUpdating = False
'在这里输入你的路径,即你存放工作薄的文件夹
path = Application.ActiveWorkbook.path & "\"
file = Dir(path & "*.xls*")
Do While file <> ""
If file <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(path & file)
count = ThisWorkbook.Sheets.count
'选中要复制的工作表
wb.Sheets(1).Select
'将要复制的工作表复制到汇总工作簿
wb.Sheets(1).Move After:=ThisWorkbook.Sheets(count)
'wb.Close savechanges:=False
End If
file = Dir
Loop
Application.ScreenUpdating = True
End Sub
网友评论