简体   繁体   English

如何在Excel上更改文件打印设置以在打印工作簿时使用VBA打印几页

[英]How do I change the file print setting on Excel to use VBA to print several pages when printing the workbook

I would like to change the file print setting in Excel to go directly to VBA and print some of the 26 worksheets while printing the workbook. 我想在Excel中将文件打印设置更改为直接转到VBA,并在打印工作簿时打印26个工作表中的一些。 Most of the active worksheets should print, but a few of the worksheets should not print. 大多数活动工作表应打印,但一些工作表不应打印。 The workbook is a template and the number of active and printed worksheets will change with each new workbook created. 该工作簿是一个模板,活动的和打印的工作表的数量将随创建的每个新工作簿而变化。 Lastly, should the VBA code go in the "ThisWorkbook" section? 最后,VBA代码是否应放在“ ThisWorkbook”部分中?

I would use something like 我会用类似的东西

Sub PrintSheets ()
Dim Wks1 as Worksheet: set Wks1=Sheets("SheetName1")
Wks1.PrintOut Copies:=1, Collate:=True
'[...] and so on with your sheets

Where the no of copies can be changed To fully automatize the code I usualy create a new sheet called "Macro keys" where I store the sheets' name and copy count (ie A1= "SheetName1", B1="5" , A2="SheetName2", B2="10"). 可以更改副本数的位置为了使代码完全自动化,我通常创建一个名为“宏键”的新表,在其中存储表的名称和副本数(即A1 =“ SheetName1”,B1 =“ 5”,A2 = “ SheetName2”,B2 =“ 10”)。 Thus: 从而:

Sub PrintSheets ()
Dim MacroKeys as Worksheet: Set MacroKeys = Sheets("Macrokeys")
SheetName1 = Macrokeys.Range("A1").Value
SheetName1_CopyCount = Macrokeys.Range("B1").Value
Sheet(SheetName1 ).PrintOut Copies:= SheetName1_CopyCount, Collate:=True
'[...] and so on with your sheets
End Sub

Hope this helps! 希望这可以帮助!

暂无
暂无

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

相关问题 使用“打印为PDF”宏按钮时,如何禁用Excel Excel以外的工作簿打印? - How can I disable printing an excel workbook EXCEPT when using a Print-to-PDF macro button? 如何使用Excel VBA从使用文件浏览器选择的工作簿中复制工作表? - How do I use Excel VBA to copy a worksheet from a workbook selected using a file browser? 如何使用复选框将工作表作为一个文件打印为Excel VBA - How to use Checkbox to print worksheets as one file Excel VBA Excel VBA函数将数组打印到工作簿 - Excel VBA function to print an array to the workbook 如何从Excel VBA取消外部打印作业? - How do I cancel external print jobs from Excel VBA? Excel VBA:如何在不运行宏的情况下打开Excel文件,但希望在激活工作簿时运行宏? - Excel VBA: How do I open an Excel file without running macro but want macros to run when I activate workbook? 在Excel中使用VBA在不同的工作表上打印行 - Use VBA in Excel to print rows on different worksheet 如何在即时窗口中打印范围变量? Excel VBA - How can I print a range variable in the immediate window? Excel VBA 如何在VBA中更改工作簿的文件路径? - How can I change the file path of a Workbook in VBA? 如何在excel中嵌入文件,使用它然后再将新版本嵌入到excel工作簿中我是否正在为excel创建一个新的Userform控件? - How do I Embed file in excel, use it and then embed new version again into excel workbook I'm creating a new Userform control for excel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM