vba 在 excel 宏中更改打印机属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24121426/
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
Change printer properties in excel macro
提问by Tim.DeVries
Is there any way I can change printer properties to color rather than black and white in an Excel macro/Excel VBA? I would like to print in color from the macro but every time I exit excel it sets the color to black and white. I would like for the macro to set the color back to color every time I run it. This is the code I am using to print:
有什么方法可以在 Excel 宏/Excel VBA 中将打印机属性更改为彩色而不是黑白?我想从宏中进行彩色打印,但每次退出 excel 时,它都会将颜色设置为黑白。我希望宏在每次运行时将颜色设置回颜色。这是我用来打印的代码:
Workbooks("Book1.xlsm").Worksheets("Sheet3").PrintOut from:=1, To:=(i / 2) - 0.5
This prints every page effected by the macro but it does it in black and white. I have already tried this but it didn't change anything:
这将打印受宏影响的每一页,但它以黑白方式打印。我已经尝试过这个,但它没有改变任何东西:
Workbooks("Book1.xlsm").Worksheets("Sheet3").PageSetup.BlackAndWhite = False
If it isn't possible to do this in vba I would be fine with an API solution as well.
如果在 vba 中无法做到这一点,我也可以使用 API 解决方案。
回答by Jo Jo
Rather than using:
而不是使用:
Workbooks("Book1.xlsm").Worksheets("Sheet3").PrintOut from:=1, To:=(i / 2) - 0.5
You could just use:
你可以只使用:
Workbooks("Book1.xlsm").Worksheets("Sheet3").PrintOut
and you can skip:
你可以跳过:
Workbooks("Book1.xlsm").Worksheets("DoNotDelete").PageSetup.BlackAndWhite = False
Because it only changes the worksheet settings, not the print settings.
因为它只更改工作表设置,而不更改打印设置。
But as far as printing in color goes you are probably best off just creating a shortcut the same printer twice in the control panel
and set one to default color and another to default black and white. This way you can specify color or black/white just by which printer you choose.
但就彩色打印而言,您可能最好只在同一台打印机中创建一个快捷方式两次control panel
,并将一个设置为默认颜色,另一个设置为默认黑白。通过这种方式,您可以根据您选择的打印机指定颜色或黑/白。