|
Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim arr, brr(1 To 1000000, 1 To 40)
Set fso = CreateObject("scripting.filesystemobject")
rq = Format(Sheets(2).[g1], "yyyymm")
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "请选择对应文件夹"
.AllowMultiSelect = False
If .Show Then
fd = .SelectedItems(1)
Else
MsgBox "未选择有效文件夹路径", vbCritical, "警告"
End
End If
End With
For Each f In fso.getfolder(fd).Files
If InStr(f.Name, rq) Then
With Workbooks.Open(f)
arr = .Sheets(1).UsedRange
For x = 2 To UBound(arr)
If Len(arr(x, 1) & arr(x, 2)) Then
n = n + 1
brr(n, 1) = Split(f.Name, ".")(0)
For y = 1 To UBound(arr, 2)
brr(n, y + 1) = arr(x, y)
Next
End If
Next
.Close False
End With
End If
Next f
Sheets("工单列表").[a2:an1000000].ClearContents
If n > 0 Then
Sheets("工单列表").[a2].Resize(n, 40) = brr
MsgBox "已提取到" & n & "条数据!"
Else
MsgBox "未提取到数据,请核对日期!"
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|