|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 批量导出到模板()
Dim myPath, myName
Dim arr As Variant
Dim i, s As Integer, arr2(), arr1(), arr3()
Dim wb As Workbook
Set Mapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择保存结果文件的存放目录:", &H1)
If Not Mapp Is Nothing Then
Directory = Mapp.self.Path
Else
MsgBox "你没有选择保存目录!": Exit Sub
End If
Set zsj = Application.InputBox("请点选: 数据源中的任意非空单元格", Type:=8)
Set zdm = Application.InputBox("请在该表中点选 或者框选匹配需要的: 字段名", Type:=8)
zdmhh = Val(Application.InputBox("请输入总数据源中 _字段 所处的最末行号信息 为数字型 1 2 3 4....", "默认值", "1"))
arr = zsj.CurrentRegion.Offset(zdmhh - 1, 0)
Set gzbm = Application.InputBox("请点选:以什么字段名来命名新工作簿", Type:=8)
bml = gzbm.Column
For Each zdm1 In zdm
nn = nn + 1
ReDim Preserve arr1(1 To nn)
arr1(nn) = zdm1.Value
Next
myPath = ThisWorkbook.Path & "\*.xls*"
myName = Dir(myPath)
Do While myName <> ""
If myName <> ThisWorkbook.Name Then mbbm = myName
myName = Dir()
Loop
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & mbbm)
For Each Rng In arr1
tt = "原始数据中的 " & Rng & " 列匹配到模板中的对应位置:"
n = n + 1
If Rng = gzbm Then
bmxh = n
End If
Set tishi = Application.InputBox(tt, Type:=8)
Set sh = tishi.Parent
sh.Activate
scbm = tishi.Parent.Name
ReDim Preserve arr2(1 To n)
ReDim Preserve arr3(1 To n)
arr2(n) = tishi.Address(0, 0)
arr3(n) = scbm
Next Rng
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 2 To UBound(arr)
For j = 1 To UBound(arr2)
For k = 1 To UBound(arr, 2)
If arr1(j) = arr(1, k) Then
wb.Sheets(arr3(j)).Range(arr2(j)) = arr(i, k)
End If
Next
Next
bm = arr(i, bml)
wb.SaveAs Filename:=Directory & "\" & bm & ".xls"
Next i
wb.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "导出完毕!"
End Sub |
评分
-
1
查看全部评分
-
|