|
Sub 写入word打印()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i%, arr, myPath$, wdApp, wdD
Dim oFso
Set oFso = CreateObject("Scripting.FileSystemObject")
Dim d As Object
Set d = CreateObject("scripting.dictionary")
myPath = ThisWorkbook.Path & "\"
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
mb = Dir(myPath & "打印.docx")
If mb = "" Then MsgBox "找不到简报模板!": End
ar = Sheets("Sheet1").Range("A1:f" & Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
FileCopy myPath & "打印.docx", myPath & "打印\" & ar(i, 1) & "-" & ar(i, 2) & ".docx"
Set wdD = wdApp.Documents.Open(myPath & "打印\" & ar(i, 1) & "-" & ar(i, 2) & ".docx")
For j = 2 To 6
wdD.Tables(j - 1).Cell(1, 1).Range.Text = ar(i, j)
Next j
wdD.PrintOut
wdD.Close True
End If
Next i
wdApp.Quit
Set wdD = Nothing
Set wdApp = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|