简体   繁体   English

尝试在Excel中使用VBA打印特定页面(不连续)

[英]Trying to print specific pages (not continous) using VBA in excel

I have the following code and it works fine. 我有以下代码,它工作正常。 However now I am trying to print double sided and it work fine when its pages 2-3 or 5-6 but when I try to use pages 5 and 7 it prints only single sided. 但是,现在我尝试双面打印,当它的2-3或5-6页时可以正常工作,但是当我尝试使用5和7页时,它只能单面打印。

Sub thursday()

On Error GoTo errHandler
Application.ScreenUpdating = False

'add "Candy Room", "Dry Stock" if needed

Worksheets("Conc temp and cleaning").PrintOut 'print 1
Worksheets("Conc temp and cleaning").PrintOut 'print 8
Worksheets("Conc count and waste").PrintOut
Worksheets("OT temp and cleaning").PrintOut 'print 1
Worksheets("OT temp and cleaning").PrintOut 'print 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
Worksheets("Auditorium Check").PrintOut from:=1, to:=3
Worksheets("Washroom Check").PrintOut from:=2, to:=2
Worksheets("Auditorium Check").PrintOut from:=4, to:=5
Worksheets("Washroom Check").PrintOut from:=1, to:=1
Worksheets("Washroom Check").PrintOut from:=3, to:=3
Worksheets("Auditorium Check").PrintOut from:=6, to:=11
Worksheets("Washroom Check").PrintOut from:=6, to:=6
Worksheets("Washroom Check").PrintOut from:=4, to:=4
Worksheets("Auditorium Check").PrintOut from:=12, to:=13
Worksheets("Washroom Check").PrintOut from:=5, to:=5
Worksheets("Auditorium Check").PrintOut from:=14, to:=16
Worksheets("Stock count and opening").PrintOut
Worksheets("Print buttons").Activate

Application.ScreenUpdating = True
errHandler:
Application.ScreenUpdating = True

End Sub

Trying to have a code so that I can print the following; 尝试编写代码,以便我可以打印以下内容;

Worksheets("Conc temp and cleaning").PrintOut 'print 1
Worksheets("Conc temp and cleaning").PrintOut 'print 8

with only one code line, which will execute the print command with both those pages at once and will print double sided. 仅包含一个代码行,它将同时对这两个页面执行print命令,并且将双面打印。

Thanks for all the help in advance. 感谢您提前提供的所有帮助。

You will need to set the printer properties in the sub. 您将需要在子菜单中设置打印机属性。 Best advice is search therought he MSDN Microsoft website it is crazy helpful. 最好的建议是搜索搜索对他的MSDN Microsoft网站是有帮助的。 Try adding these to your code. 尝试将它们添加到您的代码中。

<SerializableAttribute>
Public Class PrinterSettings
    Implements ICloneable

Public Property Duplex As Duplex

If you are still stuck checkout the website: https://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings(v=vs.110).aspx 如果您仍然遇到问题,请访问以下网站: https : //msdn.microsoft.com/zh-cn/library/system.drawing.printing.printersettings(v=vs.110).aspx

Ended up using the following to make things work the way I wanted them to. 最终使用以下内容使事情按我希望的方式工作。 Made sure the print settings are set to duplex for all the sheets I wanted printed double sided and then used either one of the following; 确保将我要双面打印的所有纸张的打印设置都设置为双面,然后使用以下任一方法:

Worksheets (Array("Sheet1 ,Sheet2").PrintOut 工作表(Array(“ Sheet1,Sheet2”)。PrintOut

Or 要么

Worksheets ("Sheet1").PageSetup.PrintArea = "$A$1:$I$43, $J$54:$H63" Worksheets ("Sheet1").PrintOut Worksheets ("Sheet1").PageSetup.PrintArea = "" 工作表(“ Sheet1”)。PageSetup.PrintArea =“ $ A $ 1:$ I $ 43,$ J $ 54:$ H63”工作表(“ Sheet1”)。PrintOut工作表(“ Sheet1”)。PageSetup.PrintArea =“”

Hopefully this helps anyone else if they are trying to do the same thing, and thanks Ben for helping out :) 希望这对其他人尝试做同样的事情有所帮助,并感谢Ben帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM