|
Sub TEST()
Dim wdApp As Word.Application, wdDoc As Word.Document, strFileName$, strPath$
Dim ar, i&, j&, f$, pic As InlineShape, strPicName$
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "准考证模板.docx"
If Dir(strFileName) = "" Then MsgBox "模板.docx文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
ar = [A1].CurrentRegion
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = New Word.Application
'wdApp.Visible = True
End If
br = Array(2, 4, 7, 9, 11)
For i = 2 To UBound(ar)
Set wdDoc = wdApp.Documents.Open(strFileName)
f = strPath & "\准考证\" & ar(i, 2)
strPicName = strPath & "照片\" & ar(i, 2) & ".jpg"
With wdDoc
With .Tables(1)
For j = 2 To UBound(ar, 2)
.Range.Cells(br(j - 2)).Range.Text = ar(i, j)
Next j
Set pic = .Range.Cells(5).Range.InlineShapes.AddPicture(strPicName)
End With
End With
wdDoc.SaveAs f: wdDoc.Close
Next i
If Err <> 0 Then
wdApp.Quit
End If
Set wdApp = Nothing: Set wdDoc = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|