|
Sub 批量生成()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim arr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "银行卡账户信息.xlsx")
ff = Dir(lj & "工资银行卡明细.xlsx")
If f = "" Then MsgBox "找不到银行卡账户信息文件!": End
If ff = "" Then MsgBox "找不到工资银行卡明细文件!": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range(.Cells(1, 1), .Cells(r, 3))
End With
wb.Close False
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = i
End If
Next i
Set f = Nothing
Set obmapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件目录:", 0, 0) '浏览文件对话框
If obmapp Is Nothing Then End '如果对话框选择了 确定 按钮
fp = obmapp.Self.Path & "\" '取得选择的文件夹的路径
f = Dir(fp & "*.xls*")
Do While f <> "" ''在目录中循环
Set wb = Workbooks.Open(fp & f) '打开文件
With wb.Worksheets(1) '再打开文件的第一个工作表循环
rs = .Cells(Rows.Count, 2).End(xlUp).Row
br = .Range("a5:br" & rs)
End With
wb.Close False
n = 0
ReDim arr(1 To UBound(br), 1 To 6)
For i = 1 To UBound(br)
n = n + 1
For j = 1 To 3
arr(n, j) = br(i, j)
Next j
arr(n, 6) = br(i, 70)
xh = d(br(i, 2))
If xh <> "" Then
arr(n, 4) = ar(xh, 2)
arr(n, 5) = ar(xh, 3)
End If
Next i
Set ww = Workbooks.Open(lj & ff, 0) '打开文件
With ww.Worksheets(1)
.[a4].Resize(n, UBound(arr, 2)) = arr
End With
ww.SaveAs Filename:=lj & f
ww.Close
f = Dir
Loop
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|