|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim wordapp As Word.Application
- Dim worddoc As Word.Document
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:g" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 2))(i) = Empty
- Next
- End With
- Set wordapp = New Word.Application
- wordapp.Visible = True
- For Each aa In d.keys
- wordname = ThisWorkbook.Path & "\承包书_" & aa & ".doc"
- FileCopy ThisWorkbook.Path & "\承包书.doc", wordname
- Set worddoc = wordapp.Documents.Open(Filename:=wordname)
- worddoc.Select
- With worddoc
- With .Tables(1)
- For i = 2 To 4
- For j = 2 To 6
- .Cell(i, j).Range.Text = Empty
- Next
- Next
-
- .Select
- wordapp.Selection.MoveUp wdLine, 1, wdMove
- wordapp.Selection.EndKey wdLine
- wordapp.Selection.TypeText aa
- m = 1
- For Each bb In d(aa).keys
- m = m + 1
- For j = 3 To 7
- .Cell(m, j - 1).Range.Text = arr(bb, j)
- Next
- Next
- End With
- .Close True
- End With
- Next
- wordapp.Quit
- Set wordapp = Nothing
- Set worddoc = Nothing
- Application.ScreenUpdating = True
- MsgBox "一户一档数据生成完毕!"
- End
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|