Option Explicit
Sub HzWb()
Dim bt As Range, r As Long, c As Long
r = 1 'r是表头的行数
c = 15 'c是表头的列数,根据表头数据更新
Dim wt As Worksheet
Set wt = ThisWorkbook.Worksheets(1) '将汇总表赋给变量wt
wt.Rows(r + 1 & ":1048576").ClearContents ' 清除汇总表中原表数据,只保留表头
Application.ScreenUpdating = False ' 防止页面刷新
Dim FileName As String, sht As Worksheet, wb As Workbook
Dim Erow As Long, fn As String, arr As Variant
FileName = Dir(ThisWorkbook.Path & "\*.csv")
Do While FileName <> ""
If FileName <> ThisWorkbook.Name Then ' 判断文件是否是汇总数据的工作簿
Erow = wt.Range("A1").CurrentRegion.Rows.Count + 1 ' 取得汇总表中第一条空行行号
fn = ThisWorkbook.Path & "\" & FileName '将第1个要汇总的工作簿名称赋给变量fn
Set wb = GetObject(fn) ' 将变量fn 代表的工作簿对象赋给变量wb
Set sht = wb.Worksheets(1) ' 将要汇总的工作表赋给变量sht
' 将工作表中要汇总的记录保存在数组arr里
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(1048576, "B").End(xlUp).Offset(0, c))
' 将数组arr 中的数据写入工作表
wt.Cells(Erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
wb.Close False
End If
FileName = Dir ' 用Dir 函数取得其他文件名,并赋给变量
Loop
Application.ScreenUpdating = True
End Sub