|
求助下大家,以下宏,是将工作簿导入
但所有文件是同一个目录
如运行宏时,选择文件夹(文件夹中有拟导入的文件),应要怎么改一下?谢谢
Sub ykcbf() '//2023.4.21
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim arr, brr, d, p, f
Set d = CreateObject("Scripting.Dictionary")
Dim tm: tm = Timer
a = [{"214","SA"}]
b = [{"214","216"}]
For i = 1 To 2
d(a(i)) = b(i)
Next
Set zwb = ThisWorkbook
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.xls*")
Do While f <> ""
For Each k In d.keys
If InStr(f, k) Then
With Workbooks.Open(p & f, 0)
arr = .Sheets(1).UsedRange
.Close False
End With
zwb.Sheets(d(k)).[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
Exit For
End If
Next
f = Dir
Loop
Application.ScreenUpdating = True
MsgBox "运行完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
End Sub
|
|