|
'怪事,2010版出错2016版就能用,搞不懂,晕死。
Option Explicit
Const FIRST As Long = 51053, LAST As Long = 52203 '开始、结束
Sub test()
Dim filename(), i, j, k, kk, n, arr
If Not getfilename(filename, ThisWorkbook.Path, ".xls") Then MsgBox "!": Exit Sub
For i = 1 To UBound(filename)
With GetObject(filename(i))
arr = ActiveSheet.UsedRange
If i = 1 Then ReDim brr(1 To Rows.Count, 1 To UBound(arr, 2))
For j = 1 To UBound(arr, 1)
If arr(j, 1) >= FIRST And arr(j, 1) <= LAST Then
n = n + 1
For k = 1 To UBound(arr, 2): brr(n, k) = arr(j, k): Next
End If
Next
.Close
End With
Next
With [o1]
.Resize(Rows.Count - 1, UBound(brr, 2)).ClearContents
If n > 0 Then .Resize(n, UBound(brr, 2)) = brr
End With
End Sub
Function getfilename(filename, pth, mark) As Boolean
Dim f, n
If Right(pth, 1) <> "\" Then pth = pth & "\"
f = Dir(pth & "*.*")
Do While Len(f) > 0
If LCase(Right(f, Len(mark))) = LCase(mark) Then
n = n + 1: ReDim Preserve filename(1 To n)
filename(n) = pth & f
End If
f = Dir
Loop
If n > 0 Then getfilename = True
End Function |
|