|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_单击()
Dim myPath$, myFile$, AK As Workbook, aRow%, tRow%, i As Integer
Application.ScreenUpdating = False '冻结屏幕,以防屏幕抖动
lj = ThisWorkbook.Path & "\excel表收集\" '把文件路径定义给变量
Dim br()
ReDim br(1 To 10000, 1 To 11)
f = Dir(lj & "*.xls*") '依次找寻指定路径中的*.xls文件
Do While f <> "" '当指定路径中有文件时进行循环
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f) '打开符合要求的文件
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a2:h" & r - 2)
xm = .Cells(r, 8)
End With
wb.Close False
For i = 3 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
n = n + 1
br(n, 1) = ar(1, 2)
br(n, 2) = ar(1, 8)
br(n, 3) = xm
For j = 1 To 7
br(n, j + 3) = ar(i, j)
Next j
End If
Next i
End If
f = Dir
Loop
With ActiveSheet
.UsedRange.Offset(2) = Empty
.[a3].Resize(n, UBound(br, 2)) = br
.[a3].Resize(n, UBound(br, 2) + 1).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True '冻结屏幕,此类语句一般成对使用
MsgBox "汇总完成,请查看!", 64, "提示"
End Sub
|
|