Generating Dynamic QR Codes

Written by Allen Wyatt (last updated May 1, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


Gary is writing a large book that uses quite a few illustrations. In the caption for each illustration he uses a field for the illustration number. In the caption he would also like to have a QR code that references a URL on his website that includes, as part of the URL, the illustration number. Gary wonders if there is a way to create such a QR code within Word, without the need to utilize some external program or website.

To accomplish this task you can use a very esoteric field within Word. First, though, it is important to understand how Gary is generating his illustration numbers. He indicates that he is using a "field for the illustration number" in "the caption for each illustration." Captioning and numbering can be done automatically by Word. How you add such captions is described more fully in this WordTip:

https://tips.net/T6267

The captioning is implemented using text, a field, and a style. The caption text you specify in the Caption dialog box is inserted in a new paragraph below the figure, the paragraph is formatted using the Caption paragraph style, and the number is implemented using a SEQ field. This is all done automatically by Word, when you insert the caption. You can see this if you add the caption, position the insertion point immediately before the figure number, and then press Shift+F9. Word displays the field code:

{ SEQ Figure \* ARABIC }

Using the SEQ field allows the figure numbers to be updated if you move the figures and captions around in your document. Although it may not be evident at first, it is this flexibility—implemented through the caption's SEQ field—that makes the solution to Gary's task tricky. (You might think it is the QR code, but it isn't. More on that in a moment.)

Remember that Gary wants to include the "illustration number" within the URL that is used by the QR code. This means that not only is it necessary for the figure number in the caption to be changeable, but the URL needs to be changeable, as well. To set this up, you need to add a bookmark that encompasses the SEQ field used in the caption. Follow these steps:

  1. If the SEQ field in the caption is not already collapsed, put the insertion point within the field code and then press Shift+F9. The field code should collapse to a number—the figure number.
  2. Select the actual figure number, the one generated by the field code. (This is very important. The entire figure number needs to be selected. Do this by placing the insertion point immediately before the figure number, hold down the Shift key, and press the Right Arrow key one time.)
  3. Display the Insert tab of the ribbon.
  4. Click the Bookmark tool. Word displays the Bookmark dialog box.
  5. Type the name you want to use to refer to this figure number. For instance, if the figure is a picture of a desk, you could use a name similar to Desk2719. The important thing is that the name not include any spaces.
  6. Click Add. Word adds the new bookmark name and closes the Bookmark dialog box.
  7. Position the insertion point at the very end of your caption.
  8. Press the Spacebar once and then press Ctrl+F9. Word inserts an empty set of field braces, and the insertion point should be within the field (between the braces).
  9. Type the following within the field braces:
  10. DisplayBarcode "https://tips.net/fig
    
  11. Press Ctrl+F9 one more time. This inserts a second set of field braces, with the insertion point in the middle.
  12. Type the following: REF Desk2719. This indicates that you want Word to use the text referenced by a bookmark named Desk2719—the name of the bookmark you defined in step 5.
  13. Press the Right Arrow key two times. This positions the insertion point immediately after the set of field braces you created in step 10. (It is important that the insertion point be immediately after the closing brace.)
  14. Type the following:
  15. .png" QR \q 3
    
  16. Press Shift+F9. Word collapses the field code and you should now see the desired QR code.

What you did was to instruct Word to add a QR code that leads to a URL that you constructed in steps 9 through 13. The text specified in step 9 is the portion of the URL before the variable figure number and the text in step 13 is the portion of the URL after the figure number. In the above steps, if the SEQ field pointed to by the bookmark named Desk2719 is 16, then the QR code will refer to the following URL:

https://tips.net/fig16.png

If your subsequent editing results in the figure number being updated, then the URL updates to reflect the new number of the figure, and the QR code updates accordingly.

If your QR Code isn't producing the desired target URL, it is most likely because you didn't put the quote marks in the right place or you added spaces that shouldn't be there. If I select the QR code and press Shift+F9, I can see the full field code, like this:

{ DisplayBarcode "https://tips.net/fig{ REF Desk2719 }.png" QR \q 3 }

Notice the opening and closing quote marks on the target URL, and that there are no spaces before or after the REF field. You will need to examine how you are specifying the URL to make sure that it is valid after the REF field is collapsed. (If you want, you can place the insertion point within the REF field and press Shift+F9 to collapse just that portion of the larger field structure.)

Note, as well, that the DisplayBarcode field must be typed in manually, as is done in step 9. This is because it is not presented as an option if you use the Field tool (Insert tab of the ribbon) to create a field. The field can create more than just QR codes; you can find more information about the field here:

https://support.microsoft.com/en-au/office/6d81eade-762d-4b44-ae81-f9d3d9e07be3

Note that if the QR code created by the above steps is too large for your needs (or not large enough), there are switches available that allow you to specify the height and width of the QR code created by the field.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10270) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting a Header or Footer

When working with existing documents, you may need to delete a header or footer previously created. Here's how you can do ...

Discover More

Generating a Power Efficiency Diagnostics Report

Your computer uses power to operate, and Windows has a great impact on how much power it uses. You can use a hidden ...

Discover More

Selecting the First Cell In a Row

When creating macros, you'll often have a need to select different cells in the worksheet. Here's how to select the first ...

Discover More

Do More in Less Time! An easy-to-understand guide to the more advanced features available in the Microsoft 365 version of Word. Enhance the quality of your documents and boost productivity in any field with this in-depth resource. Complete your Word-related tasks more efficiently as you unlock lesser-known tools and learn to quickly access the features you need. Check out Microsoft 365 Word For Professionals For Dummies today!

More WordTips (ribbon)

Inserting Page Number Cross-References

Want to insert a dynamic cross-reference to a particular page number? It's easy to do following the steps in this tip.

Discover More

Extracting INCLUDEPICTURE File Names

If you use the INCLUDEPICTURE field to add images to your document, you may love the macro in this tip. It allows you to ...

Discover More

Using the SYMBOL Field

The most common way of adding symbols to a document is to use the Symbol dialog box. There is another way, however, that ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 8?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.