|
参与一下。。。- Sub ykcbf() '//2024.3.4
- Set Fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("报修记录")
- With sh
- col = .Cells.Find("*", SearchOrder:=xlByColumns, searchdirection:=xlPrevious).Column
- For j = 1 To col
- s = .Cells(1, j) '//主表固定列号
- d(s) = j
- Next
- End With
- p = ThisWorkbook.Path & ""
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In Fso.GetFolder(p).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = Fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells.Find("*", SearchOrder:=xlByColumns, searchdirection:=xlPrevious).Column
- arr = .[a1].Resize(r, c)
- wb.Close False
- End With
- For i = 2 To UBound(arr)
- m = m + 1
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If d.exists(s) Then
- brr(m, d(s)) = arr(i, j)
- End If
- Next
- Next
- End If
- End If
- Next f
- With sh
- .UsedRange.Offset(1).Clear
- .Columns(4).NumberFormatLocal = "@"
- With .[a2].Resize(m, col)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Application.ScreenUpdating = True
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
|