Mail merge with barcodes
How to add a barcode to an existing mail merge
Word 365, 2019, 2016, 2013, 2010, 2007, 2003
Open an exisiting mail merge document or create a new one.
Add the Barcode Object to your mail merge document. Insert 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:
' 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
' Fill ActiveBarcode text property now
ActiveDocument.Barcode1.Text = ActiveDocument.MailMerge.DataSource.DataFields("Productcode").Value
' do not prompt for printing...
Options.PrintBackground = True
' print page
' recognize old record
lastone = ActiveDocument.MailMerge.DataSource.ActiveRecord
' select next record
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
num = num + 1
' check if there are new ones
Loop While ActiveDocument.MailMerge.DataSource.ActiveRecord <> lastone
' notify user
MsgBox (Str(num) + " pages printed!")
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: Do start the test printout with very few data sets, so that there are not too much misprints in the event of an error or mistake.
If you have placed the macro not in the document itself but, for example, in Normal. dot, the document must not be in design mode when you execute the macro. This will cause an error. Therefore, switch off the design mode before executing the macro.