|
Sub test()
mb = ThisWorkbook.Path & "/乡村振兴(空表).docx"
Set wd = CreateObject("word.application")
arr = [a1].CurrentRegion
For i = 2 To UBound(arr) Step 7
wjm = ThisWorkbook.Path & "\乡村振兴(" & Format(Date, "yyyy-mm-dd") & ").docx"
FileCopy mb, wjm
Set d = wd.documents.Open(wjm)
d.tables(1).Cell(1, 1) = arr(i, 1)
d.tables(1).Cell(2, 2) = arr(i, 2)
d.tables(1).Cell(2, 4) = arr(i, 3)
d.tables(1).Cell(3, 2) = arr(i, 4)
d.tables(1).Cell(3, 4) = arr(i, 5)
d.tables(1).Cell(4, 2) = arr(i, 6)
d.tables(1).Cell(4, 4) = arr(i, 7)
For j = 1 To arr(i, 5) - arr(i, 4) + 1
d.tables(1).Cell(4 + j, 2) = arr(i + j - 1, 10)
Next
d.Close
Next
MsgBox "生成完毕!"
End Sub
|
|