Word
Mail merge with barcodes

 Standard or higher

Use barcodes in Word mail merge

Word 365, 2024, 2021, 2019, 2016, 2013, 2010, 2007, 2003

1


ActiveBarcode: Use barcodes in Word mail merge.

Open an existing mail merge document or create a new one.

2


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.

ActiveBarcode: Barcode, Word


3


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

4


The result looks like this. In the screenshot, you can also see where the macro is inserted.

ActiveBarcode: Barcode, Word


5


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.

ActiveBarcode: Barcode, Word


6


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.

ActiveBarcode: Barcode, Word


7


Done.

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