|
- Sub 参考()
- On Error Resume Next
- Dim A
- Dim arr, i As Integer, n As Integer, m As Integer, strarr As String
- Dim trow As Long
- Dim WordAppX As New Word.Application
- Dim WordDocX As Word.Document
- Dim WordTableX As Word.Table
- Dim WordRowX As Word.Row
- Dim vsrange As Word.Range
- Dim myPath As String, Fn$
- trow = Sheets("9月伙食费汇总表(原始表)").Range("A65536").End(xlUp).Row '行数
- myPath = ThisWorkbook.Path
- Set WordAppX = New Word.Application
- WordAppX.Visible = False
- arr = Sheets("9月伙食费汇总表(原始表)").Range("a2:f" & trow) '数组
- For m = 1 To trow - 1
- Set WordDocX = WordAppX.Documents.Add(myPath & "\模版.docx")
- If strarr <> arr(m, 1) Then
- strarr = arr(m, 1)
- For n = m To trow - 1
- If strarr = arr(n, 1) Then
- Set WordTableX = WordDocX.Tables(1)
- i = i + 1
- WordTableX.Rows.Add
- WordTableX.Cell(i + 3, 2).Range.Text = arr(n, 3)
- WordTableX.Cell(i + 3, 3).Range.Text = arr(n, 4)
- WordTableX.Cell(i + 3, 4).Range.Text = arr(n, 5)
- WordTableX.Cell(i + 3, 5).Range.Text = arr(n, 6)
- End If
- Next n
- WordDocX.SaveAs myPath & "" & strarr & "队伙食汇总表" & ".docx"
- Set vsrange = Nothing
- Set WordTableX = Nothing
- WordDocX.Close
- i = 0
- End If
- Next m
- WordAppX.Quit
- Set WordDocX = Nothing
- Set WordAppX = Nothing
- End Sub
复制代码 |
|