|
本帖最后由 182197315 于 2016-5-22 20:35 编辑
Sub 汇总子文件的所有表格()
[A2:F600].ClearContents
Dim cPath$, s%, x%, cDir$, cFile$, Arr(1 To 10), wb As Workbook
Dim nRow%, m%, Brr(), Crr()
cPath = ThisWorkbook.Path & "\"
cDir = Dir(cPath & "*", 16)
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then wb.Close
Next
Do While cDir <> ""
If Not cDir Like ".*" Then
If GetAttr(cPath & cDir) = 16 Then
s = s + 1
Arr(s) = cDir
End If
End If
cDir = Dir
Loop
For i = 1 To s
cFile = Dir(cPath & Arr(i) & "\*.xls*")
Do While cFile <> ""
Set wb = Workbooks.Open(cPath & Arr(i) & "\" & cFile)
For x = 1 To wb.Sheets.Count
With wb.Sheets(x)
nRow = .Range("a65536").End(xlUp).Row
Brr = .Range("a2:f" & nRow).Value
nr2 = Me.Range("a65536").End(xlUp).Row + 1
Me.Range("a" & nr2).Resize(nRow - 1, 6).Value = Brr
End With
Next
wb.Close
cFile = Dir
Loop
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub 汇总指定文件夹里的表格()
[A2:F600].ClearContents
Dim cPath$, cFile$, wb As Workbook
Dim nRow%, m%, Brr()
cPath = ThisWorkbook.Path & "\A\"
cFile = Dir(cPath & "*.xls*")
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Do While cFile <> ""
Set wb = Workbooks.Open(cPath & cFile)
For x = 1 To wb.Sheets.Count
With wb.Sheets(x)
nRow = .Range("a65536").End(xlUp).Row
Brr = .Range("a2:f" & nRow).Value
nr2 = Me.Range("a65536").End(xlUp).Row + 1
Me.Range("a" & nr2).Resize(nRow - 1, 6).Value = Brr
End With
Next
wb.Close
cFile = Dir
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
评分
-
1
查看全部评分
-
|