Today, the organization needs to print bills consecutively based on the data in Excel, so the following simple vba example is written.
Sheet 2 is the ticket template to be printed, and column A in sheet 3 stores the data to be printed.
You need to automatically set A cell in Sheet2 to the data of column A in Sheet3. Each time you set it, print one.
See the specific code below.
| The code is as follows: |
Copy code |
|
Sub continuous printing ()
'
'Continuous macro printing
'
'Define variable I
Dim I
'Cycle fifteen times
For I = 1 To 15
'Sheet3 Ai data is not empty
If Sheets ("Sheet3"). Range ("A" & I) <> "Then
'Set the A1 data in Sheet2 to the Ai data in Sheet3.
Sheets ("Sheet2"). Range ("A1"). Value = Sheets ("Sheet3"). Range ("A" & I)
'Print Sheet2
Sheets ("Sheet2"). PrintOut Copies: = 1, Collate: = True
GoTo nexti
End If
Nexti:
Next
End Sub |