-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVBA_Print_Labels_Excel
More file actions
220 lines (160 loc) · 5.71 KB
/
VBA_Print_Labels_Excel
File metadata and controls
220 lines (160 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# VBA code to print labels from excel
Sub PrintCopies()
Dim printSheet As Worksheet
Dim valueSheet As Worksheet
Dim printArea As Range
Dim copiesCell As Range
Dim copies As Integer
If Application.Dialogs(xlDialogPrinterSetup).Show = True Then
'Set the worksheets
Set printSheet = ThisWorkbook.Sheets("Print")
Set valueSheet = ThisWorkbook.Sheets("Barcodes")
'Print Area 1
Set printArea = printSheet.Range("A1:E6")
Set copiesCell = valueSheet.Range("F2")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 2
Set printArea = printSheet.Range("G1:K6")
Set copiesCell = valueSheet.Range("F3")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 3
Set printArea = printSheet.Range("M1:Q6")
Set copiesCell = valueSheet.Range("F4")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 4
Set printArea = printSheet.Range("S1:W6")
Set copiesCell = valueSheet.Range("F5")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 5
Set printArea = printSheet.Range("A8:E13")
Set copiesCell = valueSheet.Range("F6")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 6
Set printArea = printSheet.Range("G8:K13")
Set copiesCell = valueSheet.Range("F7")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 7
Set printArea = printSheet.Range("M8:Q13")
Set copiesCell = valueSheet.Range("F8")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 8
Set printArea = printSheet.Range("S8:W13")
Set copiesCell = valueSheet.Range("F9")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 9
Set printArea = printSheet.Range("A15:E20")
Set copiesCell = valueSheet.Range("F10")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 10
Set printArea = printSheet.Range("G15:K20")
Set copiesCell = valueSheet.Range("F11")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 11
Set printArea = printSheet.Range("M15:Q20")
Set copiesCell = valueSheet.Range("F12")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 12
Set printArea = printSheet.Range("S15:W20")
Set copiesCell = valueSheet.Range("F13")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 13
Set printArea = printSheet.Range("A22:E27")
Set copiesCell = valueSheet.Range("F14")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 14
Set printArea = printSheet.Range("G22:K27")
Set copiesCell = valueSheet.Range("F15")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 15
Set printArea = printSheet.Range("M22:Q27")
Set copiesCell = valueSheet.Range("F16")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 16
Set printArea = printSheet.Range("S22:W27")
Set copiesCell = valueSheet.Range("F17")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 17
Set printArea = printSheet.Range("A29:E34")
Set copiesCell = valueSheet.Range("F18")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 18
Set printArea = printSheet.Range("G29:K34")
Set copiesCell = valueSheet.Range("F19")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 19
Set printArea = printSheet.Range("M29:Q34")
Set copiesCell = valueSheet.Range("F20")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
'Print Area 20
Set printArea = printSheet.Range("S29:W34")
Set copiesCell = valueSheet.Range("F21")
copies = copiesCell.Value
printArea.PrintOut copies:=copies
Set printArea = Nothing
Set copiesCell = Nothing
Set printSheet = Nothing
Set valueSheet = Nothing
Else
MsgBox "Ç åêôýðùóç áêõñþèçêå"
End If
' With ActiveSheet.PageSetup
' Set orientation as portrait
' .Orientation = xlPortrait
' Set print area
' .printArea = "A1:C10"
' Set rows and columns to repeat on each printed page
' .PrintTitleRows = "$1:$1"
' .PrintTitleColumns = "$A:$A"
' Set page margins (in points)
' .LeftMargin = Application.InchesToPoints(0.7)
' .RightMargin = Application.InchesToPoints(0.7)
' .TopMargin = Application.InchesToPoints(0.75)
' .BottomMargin = Application.InchesToPoints(0.75)
' Set header and footer margins (in points)
' .HeaderMargin = Application.InchesToPoints(0.3)
' .FooterMargin = Application.InchesToPoints(0.3)
' Set content of headers and footers
' .CenterHeader = "Center Header"
' .CenterFooter = "Center Footer"
' .LeftHeader = "Left Header"
' .LeftFooter = "Left Footer"
' .RightHeader = "Right Header"
' .RightFooter = "Right Footer"
' Scale the sheet size for printing
' .FitToPagesWide = 1
' .FitToPagesTall = 1
' Print row and column headings
' .PrintHeadings = True
' Print cell gridlines
' .PrintGridlines = True
' Set how to print comments
' .PrintComments = xlPrintNoComments
' Set print quality
' .PrintQuality = 600
' Set order to print pages
' .Order = xlDownThenOver
' Print in black and white
' .BlackAndWhite = False
' Set zoom level for print preview
' .Zoom = 100
' End With
End Sub