如何创建 VBA 代码来打印同一张纸的多份副本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17372803/
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
How can I create a VBA code to print our multiple copies of the same sheet?
提问by Andy G
I have a button in excel and I want it to print an X amount of copies. Like Say 10 so items come into stock. I want to print 10 copies. I have formula that looks up the item info. I just want a code that Prints so many times for the "quantity" that I will fill in.
我在 excel 中有一个按钮,我希望它打印 X 份副本。就像说 10 一样,所以物品有库存。我想打印 10 份。我有查找项目信息的公式。我只想要一个代码,它可以为我将填写的“数量”打印很多次。
回答by Alan Waage
ActiveWindow.SelectedSheets.PrintOut Copies:=Range("A1").Value
回答by Andy G
Essentially..
本质上..
Sub PrintXCopies()
ActiveSheet.PrintOut , , Range("A1").Value
End Sub
where the number of copies to print is in cell A1. You should add error-handling in case this is not a number, or a sensible number. Something like:
其中要打印的份数在单元格 A1 中。如果这不是数字或合理的数字,您应该添加错误处理。就像是:
Sub PrintXCopies()
If IsNumeric(Range("A1").Value) Then
If Range("A1").Value >= 1 And Range("A1").Value < 10 Then
ActiveSheet.PrintOut , , Range("A1").Value
End If
End If
End Sub