Use barcodes in Word mail merge
![]() |
A REST API-based solution is available! It runs in the cloud and requires no Windows, ActiveX or any software installation. It is also easy to use and does not require coding. |
Open an existing mail merge document or create a new one.
Add the Barcode Object into your mail merge document. Place it where you want it in the document and set the Properties of the object, such as barcode type and size.
This will look like the following screenshot, for example. Note the name of the barcode object - highlighted here in yellow. Usually this will be Barcode1.
A macro is required for the mail merge. You can add the following macro. Copy it to the Clipboard and paste it from there into the Visual Basic for Applications editor of Word:
Sub MailMerge_example_with_ActiveBarcode() ' Macro shows how to print barcodes in a mail merge. if MsgBox("Do you want to print mail merged documents?", vbYesNo, "Question") = vbYes Then 'counter to zero num = 0 'first record is number one ActiveDocument.MailMerge.DataSource.ActiveRecord = 1 Do ' Fill ActiveBarcode text property now ActiveDocument.Barcode1.Text = ActiveDocument.MailMerge.DataSource.DataFields("Productcode").Value ' do not prompt for printing... Options.PrintBackground = True ' print page ActiveDocument.PrintOut ' recognize old record lastone = ActiveDocument.MailMerge.DataSource.ActiveRecord ' select next record ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord 'count num = num + 1 ' check if there are new ones Loop While ActiveDocument.MailMerge.DataSource.ActiveRecord <> lastone ' notify user MsgBox (Str(num) + " pages printed!") End If End Sub
The result looks like this. In the screenshot, you can also see where the macro is inserted.
Now adjust the macro to your mail merger document:
If the name of your barcode object is not Barcode1, change it in the macro - left yellow mark in the screenshot.
Now you change the field name from your data source, which is to be used for the barcode. In this example, "Productcode" is used - right yellow mark in the screenshot. Change the name within the quotation marks.
Save the document and start the macro for a test print.
Tip: Start the test printout with a small amount of data so that there are fewer misprints in case of an error.
Done. If you have placed the macro in Normal.dot rather than in the document itself, the document must not be in design mode when you execute the macro. Doing so will result in an error. Therefore, switch off design mode before running the macro.