|
楼主 |
发表于 2015-10-11 14:13
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
文件经测试不能正常打印。不知道什么原理,代码不结束,打印机就不开始工作。所以把上面的代码拆分为两个,先执行奇数,再执行偶数的。
也算方便。
有懂的可以解决一下吗。
- Sub 半自动双面打印奇数页()
- Dim myPages As Integer
- Dim myBottonNum As Integer
- Dim myPrompt1 As String
- Dim myPrompt2 As String
- Dim i As Integer, s As String
-
- myPrompt1 = "在打印时发生错误,请检查你的打印机设置"
- myPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
-
- ' 取得文档页数
-
-
- If (myPages = 0) Then '如果为零,说明没有可打印内容,退出程序
- MsgBox "Microsoft Word 未发现任何可以打印的内容", 0 + 48
- Exit Sub
- End If
-
- If (myPages = 1) Then '判断是否只有一页,如果是,只打印第一页,然后退出
- Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
- wdPrintDocumentContent, Copies:=1, Pages:="1", PageType:= _
- wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
- True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
- PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
- If Err.Number = 1004 Then
- MsgBox myPrompt1, 0 + 48 '提示用户发生打印错误
- End If
- Exit Sub
- End If
- '===============奇数页打印===========
- s = ""
- i = 1
- Do While i <= myPages
- s = s & i & ","
- i = i + 2
- Loop
- ss = Left(s, Len(s) - 1) ' 去掉最后一个逗号
- Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
- wdPrintDocumentContent, Copies:=1, Pages:=ss, PageType:= _
- wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
- True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
- PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
-
- '===============奇数页打印===========
-
-
- End Sub
- Sub 半自动双面打印偶数页()
- Dim myPages As Integer
- Dim myBottonNum As Integer
- Dim myPrompt1 As String
- Dim myPrompt2 As String
- Dim i As Integer, s As String
-
- myPrompt1 = "在打印时发生错误,请检查你的打印机设置"
- myPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
-
- ' 取得文档页数
-
-
- If (myPages = 0) Then '如果为零,说明没有可打印内容,退出程序
- MsgBox "Microsoft Word 未发现任何可以打印的内容", 0 + 48
- Exit Sub
- End If
-
- If (myPages = 1) Then '判断是否只有一页,如果是,只打印第一页,然后退出
- Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
- wdPrintDocumentContent, Copies:=1, Pages:="1", PageType:= _
- wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
- True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
- PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
- If Err.Number = 1004 Then
- MsgBox myPrompt1, 0 + 48 '提示用户发生打印错误
- End If
- Exit Sub
- End If
- '===============奇数页打印===========
-
-
- '===============奇数页打印===========
-
- If myPages Mod 2 = 1 Then
- i = myPages - 1
- myPrompt2 = "请将出纸器中已打印好一面的纸取出(最后一页)并将其翻转后放回到送纸器中,然后按下""确定"",继续打印"
-
- Else
- i = myPages
- myPrompt2 = "请将出纸器中已打印好一面的纸取出并将其翻转后放回到送纸器中,然后按下""确定"",继续打印"
-
- End If
- DoEvents
- myBottonNum = MsgBox(myPrompt2, 1 + 48) '提示用户取出纸张,确认后继续打印
- If (myBottonNum = 1) Then
- '===============偶数页打印===========
- s = ""
- Do While i >= 2
- s = s & i & ","
- i = i - 2
- Loop
- ss = Left(s, Len(s) - 1) ' 去掉最后一个逗号
- Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
- wdPrintDocumentContent, Copies:=1, Pages:=ss, PageType:= _
- wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
- True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
- PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
-
- '===============偶数页打印===========
- End If
- End Sub
复制代码 |
|