VBA 打印范围从不同的工作表,只提示用户一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26303481/
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
VBA Printing ranges from different sheets and prompting the user only once
提问by Ujjwal Vaish
I have 2 ranges (fixed) in 2 different sheets which I want to print in a single file in different pages, prompting the user by the Print dialogue box only once.
我在 2 张不同的工作表中有 2 个范围(固定),我想在不同页面的单个文件中打印它们,仅通过“打印”对话框提示用户一次。
I am so far doing this:
到目前为止,我正在这样做:
Sheets("Sheet1").Select
ActiveSheet.PageSetup.PrintArea = "$A:$D"
ActiveWindow.SelectedSheets.PrintOut
Sheets("Sheet2").Select
ActiveSheet.PageSetup.PrintArea = "$A:$D"
ActiveWindow.SelectedSheets.PrintOut
But it doesn't even prompts the user even once.
但它甚至不会提示用户一次。
回答by guitarthrower
You can select multiple sheets at once, then call the PrintOut
command.
您可以一次选择多个工作表,然后调用该PrintOut
命令。
Sheets("Sheet1").Select
ActiveSheet.PageSetup.PrintArea = "$A:$D"
Sheets("Sheet2").Select
ActiveSheet.PageSetup.PrintArea = "$A:$D"
Sheets(Array("Sheet1", "Sheet2")).Select
ActiveWindow.SelectedSheets.PrintPreview
Sheets("Sheet1").Select 'Needed so that multiple sheets don't remain selected
回答by Jim Champaigne
'I was able to print to four named ranges with this code
If msgbox1 = vbOK Then
Worksheets("TP print").Activate
ActiveSheet.PageSetup.PrintArea = "TP_1A1,TP_1A2,TP_1A3,TP_1A4"
ActiveWindow.SelectedSheets.PrintOut Preview:=Preview
Worksheets("TP Orders").Activate ' Return to Enter Order screen
Else
MsgBox "Print Operation cancelled"
Exit Sub
End If
'Just give range names to the sections you want to print.
回答by Mr. Mascaro
Your only option is to copy the cells into a new sheet, set the page breaks and then use the .PrintPreview
method to show the print preview where they can change settings and call the print dialog if they choose.
您唯一的选择是将单元格复制到新工作表中,设置分页符,然后使用该.PrintPreview
方法显示打印预览,他们可以在其中更改设置并调用打印对话框(如果他们选择)。