|
本帖最后由 lsc900707 于 2017-3-21 19:33 编辑
- Sub lsc()
- Dim tim1 As Date, tim2 As Date: tim1 = Timer
- Dim mypath, myfile, m, j, wb, arr()
- Application.ScreenUpdating = False
- Sheet1.UsedRange.Offset(1, 0).ClearContents
- mypath = ThisWorkbook.Path & "\数据"
- myfile = Dir(mypath, vbDirectory)
- Do While myfile <> ""
- If myfile <> "." And myfile <> ".." Then
- If (GetAttr(mypath & myfile) And vbDirectory) = vbDirectory Then
- m = m + 1
- ReDim Preserve arr(m)
- arr(m) = mypath & myfile & ""
- End If
- End If
- myfile = Dir
- Loop
- For j = 1 To m
- myfile = Dir(arr(j) & "*.xls*")
- While myfile <> ""
- Set wb = CreateObject(arr(j) & myfile)
- With CreateObject(arr(j) & myfile)
- k = .Sheets(1).UsedRange.Rows.Count + 3
- a = .Sheets(1).Range("A5:G" & k)
- s = Split(myfile, ".")(0)
- .Close False
- End With
- With Sheet1
- .Range("A" & [b65536].End(3).Row + 1).Resize(UBound(a), UBound(a, 2)) = a
- .Range("H" & .[h65536].End(3).Row + 1).Resize(UBound(a)) = s
- End With
- myfile = Dir()
- Wend
- Next
- Set wb = Nothing
- Application.ScreenUpdating = True
- tim2 = Timer
- MsgBox Format(tim2 - tim1, "合并完成,耗时:0.00秒"), 64, "温馨提示"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|