Drawing barcode in Mcrosoft Word

Barcode in Microsoft Word

Here are some examples how to create barcodes in Word using different versions (ActiveX/COM Class) of the StrokeScribe barcode generator.

Requirements

Placing a Barcode in Word using Active Document

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

Word Ribbon->>nsert->Object

2. Look for the StrokeScribe Document:

The Object dialog in Word

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

Context menu of the barcode object

4. Select the desired barcode type and enter some text to encode in the barcode as shown on the picture:

Properties of the barcode object

You can use our barcode add-in (works with Word 2007+) to automate the above steps.

Making a Floating Barcode

To make a floating barcode, right-click the barcode and look for the:

Formatting the barcode object

Then, go to the Layout tab on the Word Ribbon and select your preferred text wrapping style:

Selecting a wrapping style for the barcode object

Placing a Barcode in Word using ActiveX

1. Switch to the Developer tab, click Insert->More Controls as shown on the picture:

Inserting an ActiveX from the Developer tab

2. Select StrokeScribe control from the list of available objects and press OK:

The More Controls dialog

3. Activate the Design Mode button on the Developer tab. Right-click the barcode object, select Properties:

The Design Mode button

4. Adjust any barcode properties you need.

Barcode property list

How to Modify the Barcode Properties in Word with VBA

1. Paste a barcode object into your document as shown here.

2. Press Alt+F11 to open VBA editor. Double-click the ThisDocument item from the VBA project tree as shown on the picture:

Adding code to the VBA project

3. Paste the following code into the VBA editor:

Sub CreateBarcode() StrokeScribe1.Alphabet = QRCODE StrokeScribe1.Text = "123ABCD" End Sub

4. Place the caret into the Sub body and press F5 to run the code. Switch back to the Word window to see the updated barcode.

Related Tutorials

Code Snippets by Barcode Type

Below we show code snippets that work with the VBA-based example. The snippets also work with the manually placed ActiveX - you will need to replace all barcode.xxx statements with StrokeScribe1.xxx. Your ActiveX object may be named differently (i.e. StrokeScribe123). You can find the object's name in the property sheet.

All Barcode Types

How to Encode a Byte Array

barcode.Alphabet = QRCODE barcode.CodePage = -1 Dim b(1 To 3) As Byte b(1) = &H11 b(2) = &H22 b(3) = &H33 barcode.Text = b

An example of QR Code with binary data:

Encoding binary data in QR COde EAN-13 barcode in Word

EAN-13/UPC-A

To create EAN-13 barcode, modify your code in the following way:

barcode.Alphabet = EAN13 barcode.Text = "123123456780"

The barcode generator checks 13-digit strings to have a correct check digit. For 12-digit values, the check digits are automatically calculated.

UPC-A

When printing UPC-A barcodes, specify 11- or 12-digit string in the Text field. The barcode generator automatically calculates checksums for 11-digit strings.

barcode.Alphabet = UPCA barcode.Text = "12345678901"

GS1 Country Codes

A list of country codes for use in EAN-13/GS1-128/GS1-DATAMATRIX.

CODE-128 barcode in Word

CODE 128

To create a CODE 128 barcode, modify your code in the following way:

barcode.Alphabet = CODE128 barcode.Text = "ANY TEXT"

How to Encode ASCII Control Characters in Code 128

barcode.Alphabet = CODE128 barcode.Text = "ABC" & Chr(9) & "DEF" ' a TAB character

Another way is to use tilde sequences:

barcode.Alphabet = CODE128 barcode.ProcessTilde = True barcode.Text = "123~x0a~x0d" ' <CR><LF> PDF-417 barcode in Word

PDF417

To create a PDF417 barcode, modify your code in the following way:

barcode.Alphabet = PDF417 barcode.Text = "123ABC"

To create a Compact PDF417:

barcode.Alphabet = PDF417 barcode.CompactPDF417 = True

How to Set Non-default Error Correction Level

barcode.Alphabet = PDF417 barcode.PDF417ErrLevel = 8

How to Fix the Number of Rows or Columns

barcode.Alphabet = PDF417 barcode.PDF417Cols = 3 barcode.PDF417Rows = 7 QR CODE barcode in Word

QR CODE

To create a QR CODE, modify your code in the following way:

barcode.Alphabet = QRCODE barcode.Text = "123ABCD"

Mobile-friendly Barcodes

Use UTF-8 encoding to make barcodes with national characters readable by mobile barcode readers.

barcode.Alphabet = QRCODE barcode.CodePage = 65001 ' 65001 = UTF-8 barcode.Text = "ΞΟΠΡΣΤΥΦ"

An example of mobile-readable QR Code that contains UNICODE characters:

Encoding UNICODE QR COde

How to Modify the Error Correction Level

barcode.Alphabet = QRCODE barcode.QrECL = H ' L or M or Q or H

How to Force the Minimum Matrix Size

barcode.Alphabet = QRCODE barcode.QrMinVersion = 11 AZTEC barcode in Word

AZTEC

To create an Aztec barcode, modify your code in the following way:

barcode.Alphabet = AZTEC barcode.Text = "ABCD123"

How to Force the Minimum Matrix Size

barcode.AztecMinLayers = 132

How to Set the Desired Error Correction Level

barcode.AztecECL = 50

How to Modify the Quiet Zone Size

barcode.QuietZone2D = 0 DATA MATRIX barcode in Word

DATA MATRIX

To create a Data Matrix barcode, modify your code in the following way:

barcode.Alphabet = DATAMATRIX barcode.Text = "ABC1234"

How to Force the Minimum Matrix Size

barcode.DataMatrixMinSize = 132

How to Modify the Quiet Zone Size

barcode.QuietZone2D = 0

ECI

Use the Extended Channel Interpretation codes ONLY if the receiving party asked you to do so. NEVER use ECI in smartphone readable barcodes.

barcode.ECI = 5;