How to Generate Data Matrix Barcodes in Microsoft Excel

A professional tutorial on using VBA macros and specialized fonts to create scannable Data Matrix 2D barcodes within your Excel spreadsheets.

1 Configure Macro Security Settings

To run the barcode encoding scripts, you must first enable Macros in Microsoft Excel.

For Excel 2000 or 2003:

Go to Tools > Macro > Security and select the Low security level.

Excel 2003 Macro Security

For Excel 2007 to 2019 / Office 365:

Office 2010 Office 2016 Office 2019

Click the Office Button/File > Excel Options > Trust Center > Trust Center Settings > Macro Settings. Choose "Enable all macros".

Excel Macro Settings

2 Set Up VBA Library References

Open the Visual Basic Editor by pressing ALT + F11.

Excel VBA Editor

Navigate to Tools > References. Click Browse and locate cruflbcs.dll.

Default Path: C:\Program Files (x86)\Common Files\Barcodesoft\FontUtil

Ensure crUFLBcs 4.0 Type Library is checked as shown below:

Excel VBA References

3 Import the Barcodesoft VBA Module

While in the VBA Editor, press Ctrl + M to import a module. Select barcodesoft.bas from your installation folder.

Missing the file? You can download the Data Matrix module here: cruflbcs.zip

Import VBA Module

4 Encode Data Using Excel Formulas

Return to your spreadsheet. You can now use the custom =datamatrix(xxx) formula. Simply use a cell reference as the parameter to generate the encoded string.

Excel Data Matrix Formula

5 Apply Font and Alignment Settings

To transform the encoded text into a visual barcode, follow these formatting steps:

A. Select the Cell

Right-click your formula cell and select Format Cells.

Format Cells Menu

B. Change Font

Go to the Font tab and select BcsDatamatrixS.

Apply Barcode Font

C. Enable Text Wrap

Go to the Alignment tab and check the "Wrap text" box. This is critical for 2D barcodes to render in a grid.

Alignment Wrap Text

Final Scannable Result

Your Data Matrix barcode is now ready! Even if small gaps appear between lines on the screen, the BcsDatamatrixS font is specifically engineered to ensure those gaps disappear upon printing, maintaining 100% scannability.

Final Excel Data Matrix result