Chapter 6. Adding QR Codes in Microsoft Office

To insert a QR Code symbol into Office document, you can create the barcode in QRCode Encoder GUI and transfer it through clipboard. In Word, you can also use the Word AddIn included in the software. Either way, you can't change the barcode because the barcode image does not have the information of the data encoded. If you need to create QR code images on the fly in a Microsoft Office program, you can select either ActiveX control or font-based. It depends on the exact situation - in some cases ActiveX control based is better and may be the only solution supported; and in other cases font-based solution is better. In this chapter we'll overview several typical scenarios.

6.1. VBA Module

Microsoft Office programs, including Word, Excel and Access, can not call DLL functions directly. Instead, you need to import the VBA module included into your document first. This module adds function to create barcode string of a QR code.

Table 6.1. List of VBA Functions (Morovia.QRCodeFontDLL5.bas)

Function PrototypeFont to UseComment
QRCodeEncode(DataToEncode As String, _
      Optional versionID As Long=0, _
      Optional ecLevel As Long=0) As String
MRV QRCodeReturns the barcode string that with DataToEncode encoded.

Note that the version and error correction level parameters are optional. So you can call the function as below:

barcodestr = QRCodeEncode("this is data")

6.1.1. To Import VBA Module

To import the QR code VBA module, perform the following steps:

  1. In Office 2003, Select ToolsMacroVisual Basic Editor to launch Visual Basic Editor. In Office 2007 and above, first enable developer tab if you can't see it. Then click on Developer tab followed by Visual Basic.

  2. Choose FileImport File. Navigate to QRCode Fonts & Encoder installation folder, by default c:\program files (x86)\Morovia QRCode Fonts & Encoder 5 [3], and select Morovia.QRCodeFontDLL5.bas.

  3. Close Visual Basic Editor and save the file.

  4. After the VBA is imported successfully, formula QRCodeEncode is available to use.

6.2. Word Mail Merge

QR Code can be crated in a mail merge word document from a data source. Note that in order for the barcode properly created, you should have the access to the data source to add an extra field that holds the barcode string. You can't just pull a field and format it with the font. This tutorial assumes an Excel data source.

  1. Import the VBA module into the Excel spreadsheet, as described in Section 6.1.1, “To Import VBA Module”.

  2. Given each column a title on row 1 if you have not done so. With this you can refer a column with its title, instead of cell reference such as $A$1.

  3. At the right side choose a blank column and at row 1 give it title barcodestring.

  4. Add a formula on row 2 of the barcodestring column that calls the function of the formula. For example, to create QR code on column A2, enter QRCodeEncode(A2, 0, 0).

  5. After pressing enter, you should see the cell filled with a string with hexadecimal characters. Highlight this cell and choose EditCopy (Ctrl+C).

  6. Select the entire range of cells in barcodestring column to paste this formula and choose EditPaste (Ctrl+V).

  7. Follow the procedures in Word to add this spreadsheet as the data source and pull the merge fields into Word document, including barcodestring field.

  8. Highlight «barcodestring» merge field and select MRV QRCode font.

  9. Click on the merge button to display merged document. The QR code should appear in the merged document. Adjust font size to adjust the barcode size.

    Tip

    If you saw blank lines inside barcode, highlight the field and select paragraph. Set spacing After and Before to 0, and Line spacing to Single/1.0.

A working example is provided in the software. See Word-MailMerge.doc and MailMerge-Data-Source.xls for details.

6.3. Using QRCode ActiveX in Word and Excel

It is straightforward to use QRCode ActiveX control in Word, and Excel. You can bind the data encoded to a cell in Excel, or change the QRcode by editing properties.

6.3.1. Inserting QRCode ActiveX into Word/Excel

You insert QRCode ActiveX control into Word/Excel documents through Insert Control command. First, make sure the control toolbox toolbar appears somewhere over the window by check the option from View | Toolbars.

At the right bottom of the Control Toolbox, click on the More Controls icon. From the pop-up menu, scroll all the way down and select Morovia QRCodeActiveX. The cursor turns into a cross-hair icon. Click on the place you'd like to place the object and drag the mouse down to draw a rectangle. Release the mouse. The barcode control now appears on the document. The barcode object fills the rectangle you just drew.

6.3.2. Editing QRCode ActiveX Object

The QRCode ActiveX object does not offer menus or toolbars for you to do the interactive editing. Instead, you can edit the barcode object by modifying the properties. The property window is accessible by right clicking on the barcode object and select Properties.

Figure 6.1. Editing QRCode Activex properties in Office programs

Editing QRCode Activex properties in Office programs

If you are familiar with Visual Basic, you know that it is the same property sheet appearing in the Visual Basic when placing the Barcode ActiveX into a form.

6.3.3. Data Binding in Excel

When creating the object in Excel, Excel adds the property LinkedCell in the property list. This additional property links the Message property to a cell. For example, to make the barcode data bound to cell G4, enter G4 in the LinkedCell property entry.

Figure 6.2. Using LinkedCell Property to Hookup with Excel Data

Using LinkedCell Property to Hookup with Excel Data

6.4. Adding QR Code in Access Reports

You can use either ActiveX control or QRcode font in Access reports. You can find example files Accesss Example (DLL).mdb and Access Example (ActiveX).mdb under the installation directory, which demonstrates the two approaches.

6.5. Adding QR Code to InfoPath

A major improvement in 5.1 release is InfoPath support. Now you can add QR code easily to an Infopath form and bind the control to a field.

6.5.1. Adding QRCode Control to Custom Controls

Follow the steps below to add QRCode Control to Custom Controls. You only need to perform this step once.

  1. Make sure that you are in Design Mode. You can activate the Design Mode by clicking on the triangle symbol

    in the Standard toolbar, or select ToolsDesign this Form... (Atl-T+M)

  2. Open the Task Pane if it is not visible by ViewTask Pane (Ctrl+F1).

    Figure 6.3. Adding QRCode control to Custom Controls in Microsoft InfoPath

    Adding QRCode control to Custom Controls in Microsoft InfoPath

  3. In the Task Pane, click on Controls...

  4. At the bottom of the Controls task pane, click Add or Remove Custom Controls.

  5. In the Add or Remove Custom Controls dialog box, click Add. From the wizard, select ActiveX Control, followed by Morovia QRCodeActiveX.

  6. On the next page, leave Don't include a .cab file selected. Click Next.

  7. In Specifying a Binding Property list, click on the Text property.

Note: Forms templates designed to be opened in a browser can't contain ActiveX controls. If you saw a warning message that ActiveX control can't be used in this template, uncheck Design a form template that can be opened in a browser or InfoPath option. This option is accessible through ToolsForm OptionsCompatibility.

6.5.2. Inserting Barcode into Form Template

After you added QRCode control to the Custom Controls in Microsoft InfoPath, you can add a barcode to form template.

  1. Adjust or resize the form to create space for the control. Drag the control and drop to the place. A small barcode will appear at the place.

  2. Right click on the control. From the menu you can change the binding to another field on the form using Changing binding... To change the appearance of the barcode, select Morovia QRCodeActive Properties... Click on QRCodeCtrl Properties tab.

    There are a number of properties to change. Here we click on ForeColor edit box and change the foreground color to red. Click on ModuleSize edit box and change it to 40 mils. Properties changed have their values displayed in crimson color. Click on the Apply to apply the changes. The barcode on the design form changed accordingly.

  3. After saving and/or publishing the modified form, the barcode should appear. The barcode field will be automatically updated after that field is edited and the cursor is moved to another field.



[3] On 32-bit Windows the directory is c:\program files\Morovia QRCode Fonts & Encoder 5