|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 批量导出到模板3()
Dim ar, br(), cr, i%, j%, wb1 As Workbook, wb2 As Workbook, wb As Workbook, d As Object
Set wb1 = ThisWorkbook
ar = wb1.Sheets("数据").Range("a2:bo" & Cells(Rows.Count, 1).End(xlUp).Row)
ReDim br(1 To UBound(ar) + 1, 1 To UBound(ar, 2))
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
br(1, j) = Replace(Cells(1, j).Address(False, False), "1", "") & "列"
br(i + 1, j) = ar(i, j)
Next j
Next i
Set wb2 = Workbooks.Open(wb1.Path & "\模板2.xls")
For m = 1 To UBound(ar)
For j = 2 To UBound(br, 2)
d(br(m + 1, 1) & "-" & br(1, j)) = br(m + 1, j)
Next j
Set wb = Workbooks.Add
wb2.Sheets.Copy before:=wb.Sheets(1)
With wb.Sheets("工作表1")
cr = .UsedRange
For i = 4 To UBound(cr)
For j = 1 To UBound(cr, 2)
If Right(cr(i, j), 1) = "列" Then
.Cells(i, j) = d(ar(m, 1) & "-" & cr(i, j))
End If
Next j
Next i
.Cells(5, 10).Value = ar(m, 1)
End With
wb.SaveAs (wb1.Path & "\" & ar(m, 2) & ".xlsx")
wb.Close
d.RemoveAll
Next m
MsgBox "导出完毕!"
End Sub |
评分
-
1
查看全部评分
-
|