PDF417 in Microsoft Excel
Some examples how to produce PDF417 barcodes in Excel with our barcode generator.
Features
The PDF417 generator provides the following features:
- Allows to create compact (or truncated) PDF417 barcodes;
- It is possible to manually select an error correction level for PDF417 barcodes;
- Barcodes can be created with fixed number of rows or columns;
- The vertical and horizontal quiet zone widths can be changed;
- The module aspect ratio can be changed.
Setup
- Download and install the barcode generator.
Placing PDF417 in Excel Using Office Ribbon Add-in
If you need to insert a single barcode, use our Ribbon Add-in. It is just a helper to insert ActiveDocument or ActiveX instances of the barcode generator in easy way.
The picture below shows how to insert a PDF417 barcode:
After inserting, double-click the barcode to edit it's properties. On the General tab, enter a text to encode in the barcode. On the Code specific tab, you can fix the number of rows and columns.
See more information about barcode properties in the PDF417 Customization section.
Placing PDF417 in Excel Using Active Document
An example how to use the Active Document version of StrokeScribe barcode generator to create and customize PDF417 in Excel.
The Active Document is easy to insert but provides less customizations. If you need to create a dynamic barcode by linking the object to a cell, use the ActiveX-based method.
1. On the Insert tab on the Ribbon, click Object.
2. Look for the StrokeScribe Document in the dialog:
3. Right-click the barcode object, select StrokeScribe Control->Properties from the context menu.
- Go to the General tab in the barcode properties dialog;
- Set Alphabet = PDF417;
- Type any text in the Text field.
PDF417 Customization
Switch to the Code-specific 2 tab in the barcode properties dialog.
Here, you can set the error protection level and fix the number of rows/columns. More properties are available in the ActiveX/Class/DLL versions of the barcode generator.
If the error protection level is set to -1, the barcode genertor will automatically choose an optimal error correction level. The value of 0 forces to use the weakest error correction and produces a small barcode. The value of 8 gives the best data protection but increases the barcode size.
How to Remove a Border Around the Barcode
Use this example from the Excel barcode generation guide.
Compact/truncated PDF417
To create a truncated version of a PDF417 barcode, set the Alphabet property as shown below. This option is available only when creating barcodes programmatically.
StrokeScribe1.CompactPDF417 = True
Placing PDF417 Barcode in Excel Using ActiveX
The ActiveX-based barcode generation may require some programming but allows to produce PDF417 in bulk quantities.
1. Switch to the Developer tab on the Excel Ribbon and click Insert->More Controls as shown below.
2. Select StrokeScribe Control from the list of available objects and press OK:
3. Click anywhere on the worksheet to insert the barcode object.
4. Activate the Design Mode button on the Developer tab.
4.1. Right-click the barcode object, select Properties or activate the Properties button on the Ribbon:
5. Use the property list to customize your barcode. To create a PDF417, modify the following properties:
Linking PDF417 to a Cell
To automatically update the barcode when a cell content changes, use the linked cell technique.
PDF417 Customization with VBA
1. Press Alt+F11 to open VBA window. Double-click the current worksheet name in the VBA project tree:
2. Paste the following code into the VBA editor:
Sub CreateBarcode()
StrokeScribe1.Alphabet = PDF417
StrokeScribe1.Text = "123ABCD" ' Any text to encode in the barcode
' Optional PDF417 parameters:
StrokeScribe1.Rotation = 90
StrokeScribe1.PDF417ErrLevel = 3 ' Optional error correcion level
StrokeScribe1.CompactPDF417 = 1 ' Creates a Compact PDF417 barcode
StrokeScribe1.PDF417Cols = 3 ' Fixed number of the data columns
End Sub
3. Place the caret into the Sub body, press F5 to run the code and switch back to the Excel window to enjoy the barcode.
To encode data from a cell, use the following code:
StrokeScribe1.Text = Range("A1")
A formula-based example of making PDF417 in Excel
Open the VBA window (Alt+F11) and create a standard module (VBAProject->Insert->Module).
Copy the following code into the module:
Function CreateBarcode(data As String) As String
Dim AC As Range
Set AC = Excel.Application.Caller
Dim wsh As Worksheet
Set wsh = AC.Worksheet
shname = "barcode_" & AC.Address()
On Error Resume Next
wsh.Shapes(shname).Delete
On Error GoTo 0
bar_w = AC.MergeArea.Width
bar_h = AC.MergeArea.Height
Dim ss As StrokeScribeClass
Set ss = CreateObject("STROKESCRIBE.StrokeScribeClass.1")
ss.Alphabet = PDF417
ss.Text = data
image_path = Environ("TEMP") & "\pdf417.wmf"
rc = ss.SavePicture(image_path, WMF, 1440, 1440 / (bar_w / bar_h))
If rc > 0 Then
CreateBarcode = ss.ErrorDescription
Exit Function
End If
Dim shp As Shape
Set shp = wsh.Shapes.AddPicture(image_path, msoFalse, msoTrue, AC.Left, AC.Top, bar_w, bar_h)
shp.Name = shname
Kill image_path
CreateBarcode = ""
End Function
Add a reference to the StrokeScribe Class into your VBA project.
Switch back to the Excel window.
Choose a cell and type in the formula field:
=CreateBarcode("Some text to encode in the PDF417")
PDF417 customization
Use the Rotation property to rotate barcode to 90, 180, 270 degrees:
ss.Rotation = 90
Use the PDF417ErrLevel to manually define the error correction level:
ss.PDF417ErrLevel = 3
This will create a compact/truncated PDF417 barcode:
ss.CompactPDF417 = 1
If you need to fix the number of rows or coumns:
ss.PDF417Cols = 5
For the more detailed step-by-step tutorial, visit making barcodes with formula.
A DLL-based example of making PDF417 in Excel
The VBA code creates a barcode picture in vector format (WMF) in a temporary file and then loads it into a Shape object. This method does not require ActiveX/COM server or font installation and produces small-sized, scalable barcodes.
Private Declare PtrSafe Function Initialize Lib "StrokeScribeDL64.dll" () As Long
Private Declare PtrSafe Function SetLongPropU Lib "StrokeScribeDL64.dll" _
(ByVal name As LongPtr, ByVal val As Long) As Long
Private Declare PtrSafe Function SetTextPropU Lib "StrokeScribeDL64.dll" _
(ByVal name As LongPtr, ByVal val As LongPtr) As Long
Private Declare PtrSafe Function SavePictureU Lib "StrokeScribeDL64.dll" _
(ByVal filename As LongPtr, ByVal format As Long, ByVal w As Long, ByVal h As Long, _
ByVal dpi As Long) As Long
Private Const PDF417 = 6
Private Const WMF = 7
Private Sub barcode()
Dim wsh As Worksheet
Set wsh = ActiveSheet
Dim rc As Long
rc = Initialize()
If rc <> 0 Then
Debug.Print "Initialize() failed, error code = " & rc
Exit Sub
End If
SetLongPropU StrPtr("Alphabet"), PDF417
Dim text As String
text = "some text to encode in PDF417"
rc = SetTextPropU(StrPtr("Text"), StrPtr(text))
If rc > 0 Then
Debug.Print "SetTextProp() failed, error code: " & rc
Exit Sub
End If
Dim pic_path As String
pic_path = Environ("TEMP") & "\barcode.wmf"
rc = SavePictureU(StrPtr(pic_path), WMF, 300, 100, 0)
If rc > 0 Then
Debug.Print "SavePicture() failed, error code: " & rc
Exit Sub
End If
On Error Resume Next
wsh.Shapes("barcode").Delete
On Error GoTo 0
Dim shp As Shape
Set shp = wsh.Shapes.AddPicture(pic_path, msoFalse, msoTrue, 1, 1, _
Application.CentimetersToPoints(3), Application.CentimetersToPoints(3))
shp.name = "barcode"
Kill pic_path
End Sub
For more examples, visit the programming examples section in the DLL documentation.
Related Tutorials
- Barcode in Microsoft Excel
- Using Formula to Create Barcode in Excel
- Using DLL version of the barcode generator in Excel
© 2026 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.