RomânăEnglish
Gadgetisimo » PCs » Automatic QR Code Insertion in Microsoft Office, CorelDraw and LibreOffice

Automatic QR Code Insertion in Microsoft Office, CorelDraw and LibreOffice

  1. Introduction
  2. Getting the QR code
  3. Automatic QR code insertion in Microsoft Office and VBA
  4. Automatic QR code insertion in CorelDraw and VBA
  5. Automatic QR code insertion in LibreOffice and Basic

Introduction

I don’t think we still need to talk about the advantages of QR codes compared to barcodes. Their widespread use speaks for itself. The big advantage is that we can encode (almost) anything.

On top of that, the more information we need to encode, the more the width of the barcode has to increase, because the thinnest bar and the smallest distance between bars have lower limits, determined by the readability that must be provided to the barcode reader, which is an optical system. See, for example, the codes on invoices. The same amount of information can be encoded as a QR code on a much smaller area. Of course, QR codes also have a readability issue. The more information we cram into the same area, the more complex the QR code becomes.

Practically, for the same area, the black and white squares get smaller, and if we hit the readability limit, we’ll have to increase the size of the QR code. But the required area is much smaller than in the case of barcodes.

Getting the QR code

There are countless websites that offer free QR code generation. And CorelDraw offers QR code insertion directly in the application.

CorelDraw - Insert QR code from the application
CorelDraw – Insert QR code from the application

But what we’re interested in is automation, to insert multiple QR codes simply and quickly. For example, we need to make 100 labels for 100 different products. We’ll create a file with the necessary information (in tabular format) and from that we’ll generate 100 QR codes with a single run of a VBA or Basic function. One hundred times, yes, but we’re not the ones doing the running 😀.

To do this we’ll use a website that lets us download a QR code (a file containing the QR code image) after accessing a link. We’ll generate that link ourselves, based on the information we want to appear in the QR code. In the code we’ll also insert other information related to the QR code, for example the graphic file format we want (SVG, PNG, JPG or others).

For example, by accessing the link https://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Fgadgetisimo.ro%2F, we get this QR code, which takes us to our website address:

QR code example
QR code example

The main site we’re using is QR Code Generator. On the first page you’ll find all kinds of specific generators: URL (web address), text, e-mail, etc. But we’ll use the API created exactly for what we need, at goqr.me/api. There you’ll find all the information you need. We’ll be creating QR codes, so we’ll use the documentation at goqr.me/api/doc/create-qr-code/. Read it all, carefully. There we learn something very important: there is no request limit, but you should keep it under 10,000 requests per day. No account is required, and the service is completely free. Let’s hope they stay on the market for as long as possible.

The format of the link we’ll use is:

https://api.qrserver.com/v1/create-qr-code/?data=strTextQR&ecc=H&format=svg

where strTextQR is the text we want to encode. You’ll find the other two parameters (ecc and format) in the API documentation.

The general logic of the code is as follows:

  1. Get the text to be encoded, strTextQR, from the file we mentioned at the beginning. How we obtain this text is not the subject of this article.
  2. Build the link. Here we’ll use strTextQR, then modify it so that it’s acceptable from a web link point of view. Not every character can be part of a web link. For example, the colon : character appears immediately after https and only there. If it appears somewhere inside strTextQR, the link is not correctly formed and will not be accessible. That’s why it has to be replaced with its Hex equivalent, which is 3A. And for the browser to know that a Hex code follows, we put the % character in front: %3A. The function for this transformation is URLencode().
  3. Download the file we receive when we access the link built with strTextQR. Here we use the DownloadFile() and URLDownloadToCacheFile() functions.
  4. Insert the downloaded file into the desired document. For this we use the QR_Insert() procedure.
  5. Move on to the next text in the tabular file.

Automatic QR code insertion in Microsoft Office and VBA

Almost the entire VBA code is common to any Microsoft Office application; the difference is at the end, lines 28–54. You’ll use the line(s) of code specific to each application in the Microsoft Office suite.

Usage examples:

Call QR_Insert("https://gadgetisimo.ro/")
Call QR_Insert("John Doe")

The Gadgetisimo.ro – MIT License applies for open source software. See here

Automatic QR code insertion in CorelDraw and VBA

Usage examples:

Call QR_Insert("https://gadgetisimo.ro/")
Call QR_Insert("John Doe")

The Gadgetisimo.ro – MIT License applies for open source software. See here

Automatic QR code insertion in LibreOffice and Basic

The Basic code is common to any LibreOffice application.

Usage examples:

Call QR_Insert("https://gadgetisimo.ro/")
Call QR_Insert("John Doe")

The Gadgetisimo.ro – MIT License applies for open source software. See here

Until next time,

Happy Coding!

Sources: Pexels


Back To Top
Gadgetisimo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.