|
Sub lx() '笛声悠扬于2021、4、12
Dim ar, br(), i%, j%, k%, wdapp As Object, wd As Object, wd1 As Object
ar = Sheet1.Range("a2:i" & Sheet1.Range("a2").End(xlDown).Row)
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2) + 8)
Set wdapp = CreateObject("word.application")
wdapp.Visible = True
Set wd1 = wdapp.documents.Open(ThisWorkbook.Path & "\劳动合同书1.docx")
For i = 1 To UBound(ar)
br(i, 1) = ar(i, 6): br(i, 2) = ar(i, 1): br(i, 3) = ar(i, 3): br(i, 4) = ar(i, 4)
br(i, 5) = Year(ar(i, 5)): br(i, 6) = Month(ar(i, 5)): br(i, 7) = Day(ar(i, 5))
For j = 1 To 3
br(i, (j - 1) * 3 + 8) = Year(ar(i, j + 6))
br(i, (j - 1) * 3 + 9) = Month(ar(i, j + 6))
br(i, (j - 1) * 3 + 10) = Day(ar(i, j + 6))
Next j
wd1.Range.Copy
Set wd = wdapp.documents.Add
wd.Range.Paste
For k = 1 To UBound(br, 2)
wd.Activate
With wd.Range
.Find.ClearFormatting
.Find.Highlight = True
.Find.Replacement.ClearFormatting
With .Find
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
.Find.Execute
If .Find.Found = True Then
.Text = br(i, k)
.HighlightColorIndex = wdNoHighlight
End If
End With
Next k
wd.SaveAs (ThisWorkbook.Path & "\" & br(i, 2) & ".docx")
wd.Close
Next i
Set wdapp = Nothing
Set wd = Nothing
Set wd1 = Nothing
End Sub
|
|