Excel VBA 打印到特定的打印机托盘

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/770230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:23:27  来源:igfitidea点击:

Excel VBA print to specific printer tray

excelvbaexcel-vba

提问by

In Excel (2007) VBA how do I print the worksheet to a specific printer tray? This will just print to the default tray on the printer:

在 Excel (2007) VBA 中,如何将工作表打印到特定的打印机托盘?这只会打印到打印机上的默认托盘:

ws.PrintOut ActivePrinter:="\print_server\printer_name"

采纳答案by e.James

Microsoft offers one ugly solutionto this problem; using SendKeysto manually choose the correct tray from the print settings dialog box.

微软为这个问题提供了一个丑陋的解决方案;使用SendKeys从打印设置对话框中手动选择正确的纸盘。

Another option may be to set up additional printers in Windows, where each printer is actually linked to a different tray on the same printer. You could then select the appropriate tray in VBA. This articlehas the details.

另一种选择可能是在 Windows 中设置其他打印机,其中每台打印机实际上都链接到同一台打印机上的不同托盘。然后您可以在 VBA 中选择适当的托盘。这篇文章有详细信息。

Or, if your printer happens to have a different size of paper in the tray you want to print to, you can set (for example):

或者,如果您的打印机恰好在您要打印到的纸盘中有不同尺寸的纸张,您可以设置(例如):

ws.PageSetup.PaperSize = xlPaperLegal

And the printer will automatically select the correct tray. I just tried this out on my printer here, and it forced the sheet to print on the manual tray, because I don't actually have a legal size paper tray.

并且打印机会自动选择正确的纸盘。我刚刚在我的打印机上尝试了这个,它迫使纸张在手动纸盘上打印,因为我实际上没有合法尺寸的纸盘。