Adding barcodes and QR codes into Word documents and mail merges is remarkably easy though hidden from view for no good reason. There are two unlisted field codes that drop barcodes or QR codes into a Word document.
No need for special fonts, calls to web sites, VBA code or other nerd trickery. It’s all in Microsoft Word already since Word for Windows 2016. One field code is for regular Word docs, the other is to add them into mail merges.
Display Barcode
The DisplayBarcode field code makes many types of barcodes plus QR Codes.
This field code isn’t in Word’s field code menu. To insert press Ctrl + F9
to add empty field code braces, then type in the field code.
Here’s some examples then optional switches that change the look of the barcode or QR Code.
QR Code
{ DisplayBarcode “http://office-watch.com” QR \q 3 }
The \q option selects the level of error correction in the QR Code. 3 is the most error tolerant and recommended. Lower values make a simpler looking QR Code which might not work if the code is unclear or partly
QR Codes can include Wifi login details including password.
{ DisplayBarcode “WIFI:T:WEP;S:OfficeWatch;P:Fantastic;;” QR \q 3 }
This QR Code tells most devices how to login to wifi called ‘OfficeWatch’ using WEP encryption and the password ‘Fantastic’.
Word makes basic black on white QR Codes. For other colorful and clever options you need to look elsewhere, see Making QR Codes for Word and Office .
UPCA
The US standard UPC product code
{ DisplayBarcode “042100005264” UPCA }
EAN13
The global product code system, equivalent to the American UPC.
{ DisplayBarcode “042100005264” EAN13 \t }
For this example we’ve added the \t switch which adds the data/numbers below for some types of barcode.
Warning
DisplayBarcode and MergeBarcode are very fussy about the data they accept. Even spaces in UPC/EAN codes aren’t tolerated even though they are commonly added for readability.
US Postal Service address barcodes are not supported, they need special extras.
Other useful DisplayBarcode switches
There are some other useful field code switches you might need:
- \h sets a height for a barcode only in TWIPS (1/1440 inch). Microsoft doesn’t say what the default \h value is, but our informal tests suggest a value of about \h 1700.
- \r rotates the barcode or QR Code . Starting with 0 (default) then counter-clockwise 90° 1, upside-down 2 or 3.
- \f set a foreground color for the barcode or QR Code. Uses RGB values in the form 0 to 0xFFFFFF. Eg. \f 0x00FF00 turns the barcode Green
- \b sets a background color for the barcode or QR Code. Uses RGB values in the form 0 to 0xFFFFFF. Eg \b 0xFF0000 changes the background to Red.
- \t adds numbers/value below some barcodes, not QR Codes.
See Microsoft’s full documentation for details on other switches and barcode options. Note: some of the details refer to just ‘Barcode’ when they also apply to QR Codes.
Barcode or QR Code in mail merge
MergeBarcode is the same as DisplayBarcode but works inside a mail merge alongside the usual MergeField .
Say you have a unique QR Code for each person to put on a login or entry badge. To make those QR codes for each badge use the codes like
{ MergeBarcode StaffID QR } or
{ MergeBarcode StudentNumber QR }
With StaffID or StudentNumber being fields in the merge data.
All the DisplayBarcode options and switches apply. MergeBarcode adds a \a switch for Japanese Post needs.
Questions arising ….
Researching DisplayBarcode left us with a Microsoft Mysteries™
What about Excel and PowerPoint?
DisplayBarcode is great in Word but why only in Word? The same feature would be useful in PowerPoint slides while Excel users would sing hosannas if the same core code was made into a function eg DisplayBarcode().
Why not Word for Mac?
DisplayBarcode and MergeBarcode only work with Word for Windows (Office 2016 and later).
Why not in Word for Mac? The Office for Mac team at Microsoft has had nearly a decade to get its act together.
Why is DisplayBarcode a secret?
You won’t find these fields listed where they should be in Word. Insert | Text | Quick Parts | Field lists (left) MergeBarcode is AWOL in the Mail Merge category list (right)
It’s not like either field code is new. They were added (oh so quietly) in Word for Windows 2016 and now available in Word for Windows in Microsoft 365 plus Windows versions of Word 2024 Word 2021 and Word 2019 as well.