|
Sub zhz3230()
Dim Wk As Workbook, Sht As Worksheet, n As Integer, MyPath, MyName
Application.ScreenUpdating = False
Application.EnableEvents = False
n = 1
MyPath = ThisWorkbook.Path & "\" '指定路径
MyName = Dir(MyPath & "\" & "*.xls") '寻找第一项
For h = ThisWorkbook.Sheets.Count To 1 Step -1
If ThisWorkbook.Sheets(h).Name = "合并" Then
ThisWorkbook.Sheets(h).Delete
End If
Next
Set Nsh = ThisWorkbook.Sheets.Add(before:=Sheets(1))
Nsh.Name = "合并"
Do While MyName <> "" '开始循环,从这之后Sheets(1)为汇总的工作薄的第一个工作表,改为Sheets(2)则为第二个工作表,如需要改需改这之后所有的Sheets(1)为相应的表
If MyName <> ThisWorkbook.Name Then
Set Wk = Workbooks.Open(MyPath & "\" & MyName)
Wk.Sheets(1).UsedRange = Wk.Sheets(1).UsedRange.Value
s = ThisWorkbook.Sheets("合并").UsedRange.Rows.Count
Wk.Sheets(1).Range(Wk.Sheets(1).Cells(1, 1), Wk.Sheets(1).Cells(Wk.Sheets(1).UsedRange.Rows.Count, Wk.Sheets(1).UsedRange.Columns.Count)).Copy ThisWorkbook.Sheets("合并").Cells(s + 3, 1)
Wk.Close False
End If
MyName = Dir
Loop
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
|
|