PDF417 barcode in Excel

PDF417 in Excel With DLL-based generator

Table of Contents

An example how to use DLL version of StrokeScribe barcode generator and VBA to make PDF417 barcodes in Excel. This method requires good VBA knowledge.

The code below does not require .Net, COM, ActiveX or other complex technologies.

The code makes PDF417 barcodes as vector WMF pictures in temporary files. After the barcode is loaded into a shape object, you don't need the file anymore.

To update data in the barcode, the previously created picture must be deleted and replaced with a new PDF417 shape.

Setup

The Code (VBA)

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 ' The currently active Excel worksheet 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 ' Creating a PDF417 barcode Dim text As String text = "some text to encode in PDF417" ' Storing any data in the barcode 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) ' Creating a temporary picture file If rc > 0 Then Debug.Print "SavePicture() failed, error code: " & rc Exit Sub End If On Error Resume Next wsh.Shapes("barcode").Delete ' Deleting a previously created barcode (if any) 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)) ' Creating a shape object from a barcode picture shp.name = "barcode" Kill pic_path ' Deleting the temporary file End Sub

For more examples, visit the programming examples section in the DLL documentation.

Facebook X Bluesky Youtube Contacts

© 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.