本帖最后由 gwjkkkkk 于 2023-5-23 19:28 编辑
Option Explicit
Sub test()
Dim ar, br, i&, j&, strSaveName$, strFileName$, strPath$
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "目标文件.xlsx"
If Dir(strFileName) = "" Then MsgBox "目标文件不存在,请检查!", vbExclamation: Exit Sub
DoApp False
ar = [A1].CurrentRegion
br = [{5,2;5,6;11,6;8,1;11,1;22,3;14,2;17,2;8,6}]
For i = 2 To UBound(ar)
strSaveName = strPath & ar(i, 2)
With Workbooks.Open(strFileName)
With .Sheets(1)
For j = 1 To UBound(br)
.Cells(br(j, 1), br(j, 2)).Value = ar(i, j + 1)
Next j
End With
With .Sheets(3)
For j = 11 To 17
.Cells(5, j - 9).Value = ar(i, j)
Next j
End With
.SaveAs strSaveName
.Close
End With
Next
DoApp
Beep
End Sub |