Barcodes with VBA
Using and automate barcodes with VBA in Word
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 ObjectSet the standard properties (height, width) of the object using the variable 'ab':
Set ab = Selection.InlineShapes.AddOLEObject(ClassType:="ACTIVEBARCODE.BarcodeCtrl.1",
FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
ab.Width = 200You can access the properties and methods of the barcode object by using the property "OLEFormat.Object":
ab.Height = 120
ab.OLEFormat.Object.Type = 6You also can use a more cleaner way to access the properties by creating and using a variable, e.g. named 'abObject':
ab.OLEFormat.Object.Text = "987698769812"
Dim abObject As ObjectUsing 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.
Set abObject = .Object
abObject.Type = 6
abObject.Text = "987698769812"
ab.ConvertToShapeIf you do not need the control anymore you can delete it from the document:
ab.DeleteHint: 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:
DoEventsThis can be necessary, e.g. if the Control must draw itself anew.