|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_Click()
Set fso = CreateObject("scripting.filesystemobject")
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "汇总" Then sh.Delete
Next sh
Call Getfd(ThisWorkbook.Path, fso, d)
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth, fso, d)
Set ff = fso.getfolder(pth)
For Each f In ff.Files
If InStr(f.Name, ThisWorkbook.Name) = 0 Then
With Workbooks.Open(f)
For Each sh In .Sheets
If d.exists(sh.Name) Then
sh.UsedRange.Copy d(sh.Name).Cells(d(sh.Name).UsedRange.Rows.Count + 2, 1)
Else
sh.Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Set d(sh.Name) = ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End If
Next sh
.Close False
End With
End If
Next f
For Each fd In ff.subfolders
Call Getfd(fd, fso, d)
Next fd
End Sub
|
|