MS Word: Trying to dynamically update a text field when I change pictures

249 Views Asked by At

I create scannable QR codes cards in word for users to report problems. Each time I change the QRCode image, I have to change the Caption under the image to match it to the computer we are labeling. Typing this caption takes time, as 9 cards fit on a single page and each has to be updated when we insert/change the image. I'm trying to figure out how to dynamically change the caption each time I change the picture. I am adding an image as an example below. ANY Help would be appreciated.

enter image description here

I have tried looking at VB to set a label and reference the image filename (which us created with the computer name) and just remove the extension, but I can't figure out how to set the properties for the object and dynamically link them. I have little VB.Net scripting and haven't used it in almost 10 years.

1

There are 1 best solutions below

0
On

Assumning you need a solution for manual data entry into your 9 cards/labels (even though a mailmerge would work better for bulk card/label creation), if you configure each of them with:

  • a DISPLAYBARCODE field where your image shows the QR code; and
  • a text content control where your image shows the serial #,

the following ContentControlOnExit macro, placed in the 'ThisDocument' code module of your document or its template will automatically update the QR code in each label/card to match the serial # whenever its content control is exited.

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl.Range.Cells(1).Range
  .Fields(1).Code.Text = "DISPLAYBARCODE " & CCtrl.Range.Text & " QR \q 3"
  .Fields.Update
End With
End Sub