|
问题:无论如何指定打印页码,都是全部打印改文档,指定页码无效。
论坛搜索无果,在其他论坛百度搜素到一个案例,解决了。
期间测试,打印纸张无数(好在最近大量打印,也没浪费几张)。。。。
如果你也正受到这个问题的困扰,送点分。
其问题的关键我也在 代码 中指出,而且相当奇怪的是不指定页码,同一种方式居然不行!所有有了2个打印输出的写法。
word确实太奇怪了。。。。。
- Sub PrintWD()
- Rem word文件批量打印
- On Error Resume Next
- Dim fileToOpen, GetOpenFilename, App, iFile, cr
- Dim inputStr, pCop%, pPag$, WrdDOC
- fileToOpen = Application.GetOpenFilename(filefilter:="Word文档(*.do*),*.do*", FilterIndex:=4, Title:="请选择要处理的文档(可多选)", MultiSelect:=True)
- If Not IsArray(fileToOpen) Then
- Application.StatusBar = "没选择文件,退出打印。"
- Exit Sub '如果没选,则退出
- Else
- inputStr = Application.InputBox("输入提示:(份数|打印页) " & Chr(10) & "打印页按1-3,5格式输入,不输入打印所有页", "MQ批量打印", "1|")
- If inputStr = False Then Exit Sub
- 'MsgBox Split(inputStr, "|")(0)
- If Len(inputStr) > 0 Then
- If InStr(1, inputStr, "|", 1) > 0 Then
- pCop = Split(inputStr, "|")(0)
- pPag = Replace(Split(inputStr, "|")(1), ",", ",") '转换逗号
- If Len(pPag) = 0 Then pPag = ""
- 'MsgBox pPag
- Else
- pCop = inputStr
- pPag = ""
- End If
- If pCop = 0 Then pCop = 1
- 'GoTo endline
- 'On Error GoTo endline
- Set App = CreateObject("Word.Application")
- For Each iFile In fileToOpen
- Set WrdDOC = App.Documents.Open(iFile)
- 'MsgBox pPag
- If Len(pPag) > 0 Then
- App.Documents(WrdDOC).PrintOut Range:=wdPrintRangeOfPages, Copies:=pCop, Pages:=pPag, Collate:=True, Background:=True, PrintToFile:=False, _
- PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
- PrintZoomPaperHeight:=0
- App.NormalTemplate.Saved = True '指定打印页码能成功的关键 参考 http://bbs.3s001.com/thread-253796-1-2.html
- Else
- App.Documents(WrdDOC).PrintOut Copies:=pCop, Pages:="", Collate:=True, Background:=True, PrintToFile:=False, _
- PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
- PrintZoomPaperHeight:=0
- End If
- App.Documents(WrdDOC).Close False
- WrdDOC.Quit
- T = T + 1
- Next
- Set App = Nothing
- Application.StatusBar = "操作完成。打印了 " & T & " 个文件。"
- Else
- Application.StatusBar = "退出打印。"
- End If
- End If
- endline:
- 'MsgBox Err.Description
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|