|
本帖最后由 bajifeng 于 2016-10-12 20:21 编辑
- Sub 生成() 'by bajifeng
- Dim arr, i%, strPath$, br
- arr = Range("A1").CurrentRegion.Value
- Application.DisplayAlerts = False
- strPath = ThisWorkbook.Path & Application.PathSeparator
- Dim objWord As Object
- Set objWord = CreateObject("word.application")
- With objWord
- For i = 2 To UBound(arr)
- With .Documents.Add(Template:=strPath & "模板.doc")
- Application.StatusBar = "正在处理 " & Cells(i, "B")
- .bookmarks("姓名").Range.Text = Cells(i, "B")
- .bookmarks("性别").Range.Text = Cells(i, "H")
- .bookmarks("出生年月").Range.Text = Format(Cells(i, "I"), "yyyy.mm")
- .bookmarks("年龄").Range.Text = Cells(i, "j")
- If Len(arr(i, 22)) Then
- br = jtcy(arr(i, 22))
- For ii = 1 To UBound(br)
- For jj = 1 To UBound(br, 2)
- With .Tables(2)
- .Cell(4 + ii, 1 + jj).Range.Text = br(ii, jj)
- End With
- Next
- Next
- End If
- .SaveAs strPath & Cells(i, "B") & ".doc", FileFormat:=0
- .Close True
- End With
- Next
- .Quit
- End With
- Application.StatusBar = ""
- Application.DisplayAlerts = True
- MsgBox "整理完成", , "提示"
- End Sub
- Function jtcy(ByVal oCell As String) As Variant
- 'by bajifeng
- ar = Split(oCell, Chr(10))
- ReDim br(1 To UBound(ar) + 1, 1 To 5)
- For i = 0 To UBound(ar)
- tr = Split(ar(i), ",")
- For j = 0 To UBound(tr)
- br(i + 1, j + 1) = tr(j)
- Next
- Next
- jtcy = br
- End Function
复制代码 |
|