1D and 2D Barcode generation VBA macro
VBA macro able to generate the 1D Code128, EAN, Interleaved 2 of 5 and Code39 barcodes, and the 2D Data Matrix and QR Code barcodes.
The macro is able to generate the barcodes as graphical objects or as text which will be shown as the proper barcode when the companion BarsAndSpaces.ttf font is applied to the text.
Usage
The syntax of the macro is as follows:
ENCODEBARCODE(sheetIndex; cellAddress; code; codeType; outputType; params; quietZoneWidth)
sheetIndex
: index of the sheet in which the graphical object will be placed, in case of selecting that output type.cellAddress
: cell address in which the graphical object will be placed, in case of selecting that output type.code
: content to encode into the barcode.codeType
: barcode type to use. Possible values:0
: Code128 (default).1
: EAN.2
: Interleaved 2 of 5.3
: Code39.50
: Data Matrix.51
: QR Code.
outputType
: whether to generate a graphical object or just the text for which to apply the companion font. Possible values:0
: use text.1
: use a graphic object (default).
params
: codeType specific parameters. See below.quietZoneWidth
: width of the 1D codes Quiet Zone. Default value:2
.
Example:
ENCODEBARCODE(CELL("SHEET"); CELL("ADDRESS"); A2; 1; 1; 0; 2)
Code128
params
possible values:
0
: determine the code set to use automatically (default).1
: start with code set A.2
: start with code set B.3
: start with code set C.
EAN
params
possible values:
0
: automatically determine the subtype to use (default).1
: use the EAN-13 subtype.2
: use the EAN-8 subtype.3
: use the UPC-A subtype.4
: use the UPC-E subtype.- To add the check digit, increase the chosen subtype
by
8
. For example, a value of9
means to use the EAN-13 subtype and add the check digit.
Interleaved 2 of 5
No additional parameters.
Code39
params
possible values:
0
: automatically use the Full ASCII Code 39 mode.1
: always use the Full ASCII Code 39 mode (default).2
: don't use the Full ASCII Code 39 mode.- To add the Code 39 mod 43 check digit, increase the
chosen mode by
4
. For example, a value of5
means to always use the Full ASCII Code 39 mode and add the check digit.
Data Matrix
params
possible values:
0
: autodetect the encoding mode (ASCII, C40 and Text) (default).1
: force ASCII encoding mode.
QR Code
params
possible values:
0
: Error Correction (EC) level M (default).1
: EC level L.2
: EC level Q.3
: EC level H.