Excel VBA打印非连续页面时双面打印失效问题求助
Fixing Double-Sided Printing for Non-Consecutive Pages in Excel VBA
The issue you're facing boils down to how print jobs are handled: each separate PrintOut call creates its own independent print job. When you send a single page per job, your printer’s double-sided logic doesn’t kick in—it only pairs pages into front/back sides when a job has multiple pages to work with.
Here’s a revised version of your code that fixes this by grouping print requests into single jobs per worksheet, plus explicit double-sided settings to ensure consistency:
Sub thursday() On Error GoTo errHandler Application.ScreenUpdating = False ' Force double-sided printing for all worksheets (adjust flip edge if needed) Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets With ws.PageSetup .Duplex = xlDuplexFlipLongEdge ' Use xlDuplexFlipShortEdge for landscape orientation End With Next ws ' Print "Conc temp and cleaning" pages 1 + 8 in one job (instead of two separate calls) Worksheets("Conc temp and cleaning").PrintOut Pages:="1,8" Worksheets("Conc count and waste").PrintOut ' Print "OT temp and cleaning" pages 1 + 8 in one job Worksheets("OT temp and cleaning").PrintOut Pages:="1,8" Worksheets("OT count and waste").PrintOut Worksheets("Poptopia temp and cleaning").PrintOut Worksheets("Poptopia count and waste").PrintOut Worksheets("Lobby Check").PrintOut Worksheets("Xscape Check").PrintOut ' Print all required Auditorium Check pages in one job Worksheets("Auditorium Check").PrintOut Pages:="1-3,4-5,6-11,12-13,14-16" ' Print all required Washroom Check pages in one job Worksheets("Washroom Check").PrintOut Pages:="1,2,3,4,5,6" Worksheets("Stock count and opening").PrintOut Worksheets("Print buttons").Activate Application.ScreenUpdating = True errHandler: If Err.Number <> 0 Then MsgBox "Print job failed: " & Err.Description, vbExclamation Application.ScreenUpdating = True End If End Sub
Key Fixes & Explanations:
- Grouped Print Jobs: Instead of calling
PrintOutmultiple times for the same worksheet (e.g., single pages of Washroom Check), we use thePagesparameter to list all non-consecutive pages/ranges in one call. This creates a single print job per worksheet, so the printer can properly pair pages for double-sided printing. - Explicit Duplex Setting: The loop sets double-sided printing for every sheet, overriding any default printer settings that might interfere. Choose the flip edge based on your document orientation.
- Error Handling Upgrade: Added a clear error message and ensures
ScreenUpdatinggets re-enabled even if a print job fails. - Combined Duplicate Calls: Your original code printed "Conc temp and cleaning" and "OT temp and cleaning" twice (once for page 1, once for page 8). The revised code sends both pages in one job, so the printer will print page 1 on the front and page 8 on the back.
内容的提问来源于stack exchange,提问作者user9542333
相关产品推荐
相关产品推荐

