简体   繁体   中英

How can I create a VBA code to print our multiple copies of the same sheet?

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.

ActiveWindow.SelectedSheets.PrintOut Copies:=Range("A1").Value

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM