|
发表于 2016-12-21 15:04
|
显示全部楼层
本楼为最佳答案
- http://club.excelhome.net/thread-477904-1-1.html
- Sub tt()
- Dim arr, i As Integer
- Dim pic As String
- Dim Word对象 As New Word.Application
- Dim s As Integer
- Dim strPath$
- Dim newWord$, EndRow%
- arr = Range("A1").CurrentRegion.Value
- EndRow = UBound(arr)
- strPath = ThisWorkbook.Path & ""
- newWord = ThisWorkbook.Path & "\干部审批表.doc"
- FileCopy strPath & "模板.doc", newWord
- With Word对象
- .Documents.Open newWord
- .Visible = False
- .ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument '设置位置在正文
- .Selection.WholeStory '全选
- .Selection.Copy '复制
- If EndRow > 3 Then
- For i = 2 To EndRow - 1 '复制页
- .Selection.EndKey Unit:=wdStory '光标置于文件尾
- .Selection.InsertBreak Type:=wdPageBreak '分页
- .Selection.PasteAndFormat (wdPasteDefault) '粘贴
- Next i
- End If
- For i = 2 To EndRow '循环将数据写入表格内
- Application.StatusBar = arr(i, 1)
- .ActiveDocument.Tables(i * 2 - 3).Cell(1, 2).Range = Cells(i, "C") '姓名列bookmarks("姓名")
- .ActiveDocument.Tables(i * 2 - 3).Cell(1, 4).Range = Cells(i, "G") 'bookmarks("性别")
- .ActiveDocument.Tables(i * 2 - 3).Cell(1, 6).Range = Cells(i, "K") 'bookmarks("年龄")
- Next i
- .Documents.Save
- .Quit
- End With
- Application.StatusBar = ""
- MsgBox "整理完成", , "提示"
- End Sub
复制代码 |
评分
-
查看全部评分
|