Standard or higher

Word
Barcode objects with VBA

Using and automating barcodes with VBA in Word

1

You can use VisualBasic for Applications (VBA) to solve many things in Word. Here we will show you how to embed, use and delete the ActiveBarcode control with VBA:

Embedding the ActiveBarcode Control into a document:
In this example a barcode control will be placed at the cursors position. Then you can modify the object using the variable 'ab':

Dim ab As Object
Set ab = Selection.InlineShapes.AddOLEObject(ClassType:="ACTIVEBARCODE.BarcodeCtrl.1",
FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
Set the standard properties (height, width) of the object using the variable 'ab':
ab.Width = 200
ab.Height = 120
You can access the properties and methods of the barcode object by using the property "OLEFormat.Object":
ab.OLEFormat.Object.Type = 6
ab.OLEFormat.Object.Text = "987698769812"
You also can use a more cleaner way to access the properties by creating and using a variable, e.g. named 'abObject':
Dim abObject As Object
With ab.OLEFormat
.Activate
Set abObject = .Object
End With

abObject.Type = 6
abObject.Text = "987698769812"
Using the following call you can cast the barcode object in an InlineShape. Note, however, that you can change the barcode no longer after the conversion.
ab.ConvertToShape
If you do not need the control anymore you can delete it from the document:
 ab.Delete
Hint: If it's necessary that Windows process upcoming events (often named as "KeepWindowsAlive") within a macro, you can force this by using the following VBA function:
DoEvents
This can be necessary, e.g. if the Control must draw itself anew.