|
Private Sub aa()
Dim Wordapp As New Word.Application, path, fname, fullname, i, j
path = ThisWorkbook.path
lastrow = Sheets("21年").Range("B65536").End(xlUp).Row
s = 0
For i = 3 To lastrow - 1
fname = "三、HS-AQBD-079 事故调查报告 "
FileCopy path & "\模板.doc", path & "\" & fname & "(" & Sheets("21年").Range("A" & i) & ").doc"
fullname = path & "\" & fname & "(" & Sheets("21年").Range("A" & i) & ").doc"
With Wordapp
.Documents.Open fullname
.Visible = False
.ActiveDocument.Tables(1).Cell(1, 2).Range = Sheets("21年").Cells(i, 1)
.ActiveDocument.Tables(1).Cell(1, 4).Range = Sheets("21年").Cells(i, 6)
.ActiveDocument.Tables(1).Cell(1, 6).Range = Sheets("21年").Cells(i, 7)
.ActiveDocument.Tables(1).Cell(3, 2).Range = Sheets("21年").Cells(i, 3)
End With
Wordapp.Documents.Save
Wordapp.Quit
Set Wordapp = Nothing
Next i
If s = 0 Then
MsgBox "已输出到 Word 文件!"
End If
End Sub |
|