GS1 Barcodes (GS1-128 and GS1-DataMatrix) in Excel

An example how to insert linear and 2D GS1 barcodes (GS1-128 & GS1-DataMatrix) in Excel with StrokeScribe barcode generator with simple steps.

The first method of making GS1 barcodes (both GS1-128 and GS1-DataMatrix) in Excel is to insert the barcode generator as an Active Document and manually set the GS1 data string. This method of making GS1 barcodes is useful when you need a single barcode.

The second method to make GS1 barcodes - is to use formula and a small VBA script. This method allows to generate GS1-128 and GS1-DataMatrix in bulk quantities. These barcodes are hi-resolution scalable vector pictures.

Requirements

Placing GS1 barcode as an Active Document

Use this method when you need a single simple GS1 barcode with manual data entry. This method does not require programming.

1. Switch to the Insert tab on the Ribbon and click Object.

Inserting the barcode generator object in Excel as an Active Document

2. Look for the StrokeScribe Document in the list:

3. Right-click the barcode object, select StrokeScribe Control->Properties from the context menu.

The barcode generator context menu Changing the GS1 barcode properties

In this text string, we encode a batch number (AI 10), a FNC1 code (~d029), a production date (AI 11) and a product net weight (AI 310Y):

10123456~d029112501303101000055

For the GS1 data format explanation, look in the tutorials below.

Because the batch number is a variable-length value, we put a FNC1 code after it.

The production date format is YYMMDD. So the 250130 is decoded as 30-Jan-2025.

The decimal point position indicator Y in the product net weight (AI 3101Y) is encoded as shown:

Placing GS1 barcodes in Excel with formula

Making GS1 barcodes with formula is useful for bulk barcode generation. First, we write a small VBA script that call the barcode generator and produces a barcode picture in a temporary file in vector forman and then we load the barcode picture into a cell.

Second, we write a formula that calls the VBA script and provides the script with the cell's name. This method fits the barcode into a cell and works both with single and merged cells.

Unlike the most barcoding add-ons, this method refreshes the barcodes automatically when the spreadsheet content is changed and it is completely offline.

Step 1. Open the VBA window (Alt+F11) and create a standard module (VBAProject->Insert->Module).

Step 2. Paste the following code into the module:

Step 2.1. Choose between GS1-128 and GS1-DataMatrix barcode generation by modifying the Alphabet property in the code.

Step 3. Add a reference to the StrokeScribe Class into your VBA project.

Step 4. Switch back to the Excel window. Paste the following formula into the cell A1:

= "10123456" & CHAR(29) & "11250130" & "3101000055"

As in previous example, we encode the same GS1 values in the barcode: a batch number (AI 10), a FNC1 code (~d029), a production date (AI 11) and a product net weight (AI 310).

For the GS1 data format explanation, look in the tutorials below.

A formula to create GS1 barcode

Step 5. Paste this formula into a cell that is large enough to fit the barcode:

=CreateBarcodeGS1(A1) A formula to call the barcode generator

Encoding numeric values in GS1 barcodes

As you see, values like weight, length, volume do not have decimal point. Regular numbers from a spreadsheet need to be converted to GS1 format.

Paste the following function into the VBA module and then use it to convert numbers:

Public Function Y6N(txt) p = InStr(txt, ".") If p > 0 Then p = Len(txt) - p txt = Replace(txt, ".", "") v = Format$(txt, "000000") y = Format$(p, "0") Y6N = y + v End Function

An example of product net weight (AI 3101Y) conversion:

=CreateBarcodeGS1("310" & Y6N("123.456"))

These GS1 barcoding examples are compatible with all Excel versions: Excel 365, 2019, 2016, 2013, 2010 and XP;

High quality, scalable barcodes without fonts;

Compatible with GS1 general barcode specification.