|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim arr, filename(), i, j, k, m
If Not getfilename(filename, ThisWorkbook.Path, "xlsx") Then MsgBox "!": Exit Sub
ReDim brr(1 To Rows.Count, 1 To 5)
For i = 1 To UBound(filename)
If filename(i) <> ThisWorkbook.FullName And Left(filename(i), 1) <> "~" Then
With GetObject(filename(i))
arr = .ActiveSheet.[a1].CurrentRegion
For j = 1 To UBound(arr, 1)
If arr(j, 4) <> 1 Then
m = m + 1
For k = 1 To UBound(arr, 2): brr(m, k) = arr(j, k): Next
End If
Next
.Close
End With
End If
Next
With [a1]
.Resize(Rows.Count, UBound(brr, 2)).ClearContents
If m > 0 Then .Resize(m, 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 |
评分
-
1
查看全部评分
-
|