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

 ̄綄美尐妖づ 提交于 2019-12-13 07:36:26

问题


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. 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?


回答1:


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 (i.e. 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!



来源:https://stackoverflow.com/questions/19158209/how-do-i-change-the-file-print-setting-on-excel-to-use-vba-to-print-several-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!