|
参与一下。。。
- Sub ykcbf() '//2024.12.18
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("Sheet1")
- fn = CStr(sh.[m1].Value)
- rq = CDate(Format(fn, "0000-00-00"))
- rq1 = VBA.DateAdd("yyyy", -1, rq)
- fn1 = Format(rq1, "yyyymmdd")
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In fso.GetFolder(p).Files
- If fso.GetBaseName(f) = fn Then
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close False
- For i = 1 To UBound(arr)
- If arr(i, 1) <> Empty Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- End If
- Next
- m = m + 1
- End If
- Next f
- For Each f In fso.GetFolder(p).Files
- If fso.GetBaseName(f) = fn1 Then
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close False
- For i = 1 To UBound(arr)
- If arr(i, 1) <> Empty Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- End If
- Next
- m = m + 1
- End If
- Next f
- With sh
- .UsedRange.Offset(1).Clear
- .[a1].Resize(m, UBound(arr, 2)) = brr
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|