|
参与一下。。。
- Sub ykcbf() '//2024.4.6
- Application.ScreenUpdating = False
- Application.AskToUpdateLinks = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("汇集表")
- ReDim brr(1 To 10000, 1 To 100)
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p = .SelectedItems(1) & ""
- End If
- End With
- 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)
- .AutoFilterMode = False
- arr = .UsedRange
- wb.Close False
- End With
- For i = 2 To UBound(arr)
- If arr(i, 1) <> Empty Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If s <> Empty Then
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- End If
- brr(m, d(s)) = arr(i, j)
- End If
- Next
- End If
- Next
- End If
- End If
- Next f
- With sh
- .UsedRange.Clear
- .[a1].Resize(1, d.Count) = d.keys
- .[a1].Resize(1, d.Count).Interior.Color = 49407
- If m Then
- .[a2].Resize(m, d.Count) = brr
- .Range("A1").Resize(m + 1, d.Count).Borders.LineStyle = 1
- End If
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- Application.AskToUpdateLinks = True
- Application.DisplayAlerts = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|