|
楼主,我过去有一个批量打印的小宏,我改了一下,没测试打印,你自己试试吧,建议用2-3个文件的一个文件夹来打印试试,不一定正确:
- Sub 循环遍历文件夹_批量打印()
- On Error Resume Next
- Dim fd As FileDialog, i As Long, doc As Document, p As String, s As Section, j As Long, k As String, x As Long, t As Long, a$, b$
- a = InputBox("请输入起始打印页码!", "批量打印", "3")
- If a = "" Then Exit Sub
- b = InputBox("请输入终止打印页码!", "批量打印", "3")
- If b = "" Then Exit Sub
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
- Set fd = Nothing
- If MsgBox("是否打印文件夹 " & p & " ?", vbYesNo + vbExclamation, "循环遍历文件夹_批量打印") = vbNo Then Exit Sub
- k = InputBox("请输入整套打印份数!", "循环遍历文件夹_批量打印", "1")
- If k = "" Then Exit Sub
- For t = 1 To k
- With Application.FileSearch
- .NewSearch
- .LookIn = p
- .SearchSubFolders = True
- .FileName = "*.doc"
- If .Execute > 0 Then
- For i = 1 To .FoundFiles.Count
- Set doc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
- For Each s In doc.Sections
- With s.PageSetup
- If .Orientation = wdOrientLandscape Then j = 1 Else j = 0
- If .PaperSize <> wdPaperA4 Then .PaperSize = wdPaperA4: If j = 1 Then .Orientation = wdOrientLandscape
- End With
- Next
- doc.PrintOut Range:=wdPrintFromTo, From:=a, To:=b
- doc.Close savechanges:=wdDoNotSaveChanges
- Next i
- x = .FoundFiles.Count
- Else
- MsgBox "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹_批量打印": End
- End If
- End With
- Next t
- MsgBox "打印完毕!共打印 " & x & " 个文件!整套打印 " & k & " 份!", vbOKOnly + vbExclamation, "循环遍历文件夹_批量打印"
- End Sub
复制代码 |
|