Font-based barcode printing in Word

Table of Contents

An example of how to use Class based version of StrokeScribe barcode generator to draw 2D and linear barcodes in Microsoft Word with specialized TrueType barcode fonts.

How To Proceed

1. Download and install the barcode generator.

2. Open the VBA window (Alt+F11) and paste the code from the following examples into a document module:

Paste the code into VBA window

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

The examples shown here need licensed version of the StrokeScribe barcode generator. The demo version has some limitations - see the FontOut documentation.

Using linear barcode fonts in Microsoft Word

The VBA code shown below creates a 60x60mm label with a GS1-128 barcode in Word. To change the label size, modify the ps.PageWidth and ps.PageWidth settings.

To change the barcode height, set the sel.Font.Name to "StrokeScribe 1D" or to "StrokeScribe 1D Tall".

To change the barcode density, set the sel.Font.Size to 12 or 18.

Public Sub create_barcode() Dim d As Document Set d = Documents.Add Dim ps As PageSetup Set ps = d.PageSetup ' Page margins are 5mm all around ps.LeftMargin = CentimetersToPoints(0.5) ps.TopMargin = CentimetersToPoints(0.5) ps.RightMargin = CentimetersToPoints(0.5) ps.BottomMargin = CentimetersToPoints(0.5) ' Page size = 60x60mm. If you prefer inches, use InchesToPoints() ps.PageWidth = CentimetersToPoints(6) ps.PageHeight = CentimetersToPoints(6) Dim sel As Selection Set sel = d.ActiveWindow.Selection sel.ParagraphFormat.Alignment = wdAlignParagraphLeft sel.Font.Name = "StrokeScribe 1D Small" ' or "StrokeScribe 1D" or "StrokeScribe 1D Tall" sel.Font.Size = 6 ' or 12 or 18 'sel.ParagraphFormat.SpaceAfter = 0 ' Use these 2 lines with PDF417 and 2D barcodes in Word 2007+ 'sel.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle Dim ss As StrokeScribeClass Set ss = CreateObject("STROKESCRIBE.StrokeScribeClass.1") ss.Alphabet = EAN128 GS = Chr$(29) ss.Text = "10ABC123" & GS & "3111000053" & "3303123456" ' Batch Number + Product Length (Meters) + Container Gross Weight (Kg) If ss.Error Then MsgBox ss.ErrorDescription Exit Sub End If sel.Text = ss.FontOut sel.Collapse Direction:=wdCollapseEnd End Sub

When printing labels on 203DPI thermal printers, use only the following font sizes: 8, 12, 18pt. Other font sizes may cause bar width inconsistency.

To print EAN-13, make the following changes in the code:

ss.Alphabet = EAN13 ... ss.Text = "123456789012"

This will produce an UPC-A barcode:

ss.Alphabet = UPCA ... ss.Text = "12345678901"

This will produce CODE 128:

ss.Alphabet = CODE128 ... ss.Text = "123ABCD"

How to use barcode fonts in shapes in Microsoft Word

This VBA code example puts the barcode into a floating text shape. The shape can be freely positioned above the page's content.

But here is an inconvenience - Word doesn't support the TextFrame2.AutoSize and cannot automatically fit text into a shape. You will need to manually adjust the Width/Height of the shape to fit the barcode.

Public Sub create_barcode() Dim d As Document Set d = ActiveDocument Dim ss As StrokeScribeClass Set ss = CreateObject("STROKESCRIBE.StrokeScribeClass.1") ss.Alphabet = CODE128 ss.Text = "123abcd" If ss.Error Then MsgBox ss.ErrorDescription Exit Sub End If Dim sh As Shape Set sh = d.Shapes.AddTextbox(msoTextOrientationHorizontal, _ Left:=CentimetersToPoints(5), _ Top:=CentimetersToPoints(8), _ Width:=CentimetersToPoints(5), _ Height:=CentimetersToPoints(1)) sh.TextFrame.TextRange.Font.Name = "StrokeScribe 1D Tall" sh.TextFrame.TextRange.Font.Size = 12 sh.TextFrame.TextRange.Text = ss.FontOut sh.Line.Visible = msoFalse End Sub

Font embedding in Microsoft Word

By default, Word does not store fonts in the document. If you move your document to a PC that does not have a barcode font installed, barcodes are displayed with a default font (Arial or Times for example) and look like a string of random ASCII characters. You may ask all users to install the required font. But instead of this you may embed barcode fonts into the document.

In Word 2007, click the Office button, then the Word Options button. Switch to the Save tab and check the Embed fonts in the file. Click OK and save your document.

In Word 2010+, switch to the File tab on the Ribbon and select Options. In the Word Options dialog, switch to the Save tab and check the Embed fonts in the file. Click OK and save your document.

A list of available fonts

"StrokeScribe 1D xxx" - are universal fonts for linear barcodes. The fonts display Code-128/GS1-128, EAN-13/UPC-A/UPC-E, Code 39. These fonts do not support mailing barcodes and do not display human-readable characters below the barode.

All 1D-fonts have the same bar density at the same point size and optimized for printing on 203 DPI label printers.

Facebook X Bluesky Youtube Contacts

© 2025 StrokeScribe. All rights reserved. Use of any portion of this site constitutes acceptance of our Terms of Use and Privacy Policy. The website material may not be reproduced, except with the prior written permission.