|
代碼更新一下,文件夾可選擇。- Sub ykcbf() '//2024.8.4
- Set fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set sh = ThisWorkbook.Sheets("Sheet1")
- p = ThisWorkbook.Path & ""
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择原始数据文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p1 = .SelectedItems(1) & ""
- End If
- End With
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择处理后数据文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p2 = .SelectedItems(1) & ""
- End If
- End With
- For Each f In fso.GetFolder(p1).Files
- If LCase$(f.Name) Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- ReDim brr(1 To 100000, 1 To 2)
- m = 3
- With wb.Sheets("EBAResult")
- r = .Cells(Rows.Count, 5).End(3).Row
- arr = .[d1].Resize(r, 2)
- End With
- brr(1, 1) = "Length": brr(1, 2) = "PS"
- brr(2, 1) = "m": brr(2, 2) = "W/Kg"
- brr(3, 1) = "钢卷长度": brr(3, 2) = wb.Sheets("Coil").[c2].Value
- wb.Close False
- Application.SheetsInNewWorkbook = 1
- Set wb = Workbooks.Add
- For i = 2 To UBound(arr)
- m = m + 1
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = arr(i, 2)
- Next
- wb.Sheets(1).Name = "EBAResult"
- wb.Sheets(1).[a1].Resize(m, 2) = brr
- wb.SaveAs p2 & fn
- wb.Close
- End If
- End If
- Next f
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|