← Blog · How-to · 6 min read
QR Codes and Barcodes in Microsoft Word, Without an Add-in
Most people who need a QR code inside a Word document go looking for a website or an add-in. Word for Windows can already draw QR codes and barcodes itself, using two field codes that are not listed in any menu. They work well for plain codes and for mail merge. There are also two traps worth knowing about before you print a whole batch.
The two field codes
DISPLAYBARCODE draws one fixed code from text you type into it. MERGEBARCODE draws a different code for every record in a mail merge, taking the value from a column of your data. Microsoft documents both, along with the barcode types they accept:
- 2D: QR
- Retail: EAN13, EAN8, UPCA, UPCE (plus the Japanese names JAN13 and JAN8)
- Logistics and internal: CODE128, CODE39, ITF14, CASE, NW7, and the Japanese postal code JPPOST
One limit matters before anything else. Microsoft's reference states that DisplayBarcode is supported in Word for Windows (desktop). If you or the people who open your file use Word on a Mac or in a browser, do not rely on these fields.
Insert a fixed QR code
- Put the cursor where the code should appear.
- Press Ctrl+F9. Word inserts a pair of grey field braces. Braces typed from the keyboard do not work; they have to be field braces.
- Type the instruction inside them, for example:
{ DISPLAYBARCODE "https://www.example.com" QR \q 3 }
- Press F9 to update the field. Alt+F9 switches every field in the document between the code and the result, which is how you get back in to edit it.
\q sets the error-correction level for QR codes, from 0 (least) to 3 (most). Higher correction lets a scuffed or partly covered code still read, at the cost of a denser pattern. How error correction works covers the trade in more detail.
One code per record with mail merge
- Go to Mailings → Select Recipients → Use an Existing List and choose your spreadsheet.
- Where the code should go, press Ctrl+F9 and type the field with your column name, for example
{ MERGEBARCODE TicketURL QR \q 2 }.TicketURLis the column heading in your sheet. - Use Preview Results to step through a few records and check that the code changes, then Finish & Merge.
For sheets of labels, put the field in the first label and use Update Labels to copy the layout into the rest. If every label shows the same code, or an empty one, check whether the field sits inside a text box: text boxes on a label sheet can end up tied to the wrong record. Put the field directly in the label cell instead.
Trap one: you cannot set a QR code's size
Word gives you two size switches, and neither does what you might expect for a QR code.
\h sets the symbol height in twips, a unit of 1/1440 inch (about 56.7 twips per millimetre). It is meant for the bar height of a linear barcode.
\s is a scaling factor in whole percentage points, from 10 to 1000. It is a percentage of whatever size Word draws by default, and that default depends on how much you encode, because more data means more modules in the grid. People who have tried to lock the size report the same result: the printed size still varies with the data. On a sheet of badges, a longer record comes out as a bigger code.
Two ways to live with it. Keep the encoded values the same length, for example fixed-length ticket IDs rather than full web addresses. Or set the scale for your longest value, print that page first, and measure the result against the size you need. The print-size guide explains what size you actually need for a given scanning distance.
Trap two: the check-digit switch hides mistakes
EAN and UPC numbers end in a check digit calculated from the other digits. It exists to catch typing errors: change any single digit and the check digit no longer matches.
Microsoft describes the \x switch as follows: it "fixes the check digit if it's invalid". That sounds like a safety net. If a data digit was mistyped, though, \x recalculates the check digit to match the typo. The result is a perfectly valid barcode for a number that is not yours. It scans cleanly and rings up the wrong product, or nothing.
Leave \x off, and check product numbers before a merge rather than after printing. This site's barcode generator checks the digit you enter and names the one it expected, so a typo is refused instead of quietly turned into someone else's number.
Colours, rotation and the printed digits
\fand\bset the bar and background colours as hexadecimal values from0x000000to0xFFFFFF. Keep the bars dark. Red bars on white look fine to people and are invisible to the red laser in a retail scanner; the barcode guide covers the details.\rrotates the code in 90° steps, with values from 0 to 3.\tprints the encoded digits under the bars.
A retail example with the digits shown and a symbol height of 1296 twips, which is 22.86 mm, the minimum bar height GS1 gives for EAN-13 at 100% size:
{ DISPLAYBARCODE "4006381333931" EAN13 \t \h 1296 }
When Word is enough
Word's own fields are a good choice when you need plain black-on-white codes, one per record, printed from Windows. You need something else when:
- the document will be opened in Word for Mac or on the web;
- the code must be an exact size in millimetres;
- you want styled codes: colours beyond two, rounded modules, a logo in the middle;
- you want wrong product numbers refused rather than "fixed";
- the codes are needed outside Word as well.
In those cases, generate image files and insert them as pictures. The bulk generator turns a spreadsheet into one image per row, and the spreadsheet-to-labels guide walks through the whole process.
When Word’s field codes fall short: a barcode image to insert as a picture.
Make a barcode →